ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1136. Parliament

How much memory does my program need?
Posted by Juri Krainjukov 20 Dec 2002 21:37
I got "Memory limit exceeded" with this program, however I can't
understand how can it demand more than about 30

var
   n:integer;
   a:array[1..3000] of longint;     { 12 kb here }
   i,j:integer;

procedure order(i,j:integer); { In this procedure maximum is 18 kb}
var                           {becuase recursion maximum depth here}
    q:integer;            {is 3000}
begin
   {if i=j then
   begin
      write(a[i]);
      exit;
   end; }

   for q:=i to j do if a[q]>a[j] then break;

   if q<j then order(q,j-1);
   if q>i then order(i,q-1);
   write(a[j]);
   if j<>n then write(' ');

end;


begin
   readln(n);
   for I:=1 to n do read(a[i]);
   order(1,n);


end.
When I change a:array [1..3000] to a:array [1..1] It got MEMOY LIMITE 1159Kb
Posted by I am david. Tabo. 20 Dec 2002 23:44
> I got "Memory limit exceeded" with this program, however I can't
> understand how can it demand more than about 30
>
> var
>    n:integer;
>    a:array[1..3000] of longint;     { 12 kb here }
>    i,j:integer;
>
> procedure order(i,j:integer); { In this procedure maximum is 18 kb}
> var                           {becuase recursion maximum depth here}
>     q:integer;            {is 3000}
> begin
>    {if i=j then
>    begin
>       write(a[i]);
>       exit;
>    end; }
>
>    for q:=i to j do if a[q]>a[j] then break;
>
>    if q<j then order(q,j-1);
>    if q>i then order(i,q-1);
>    write(a[j]);
>    if j<>n then write(' ');
>
> end;
>
>
> begin
>    readln(n);
>    for I:=1 to n do read(a[i]);
>    order(1,n);
>
>
> end.
>
>
Re: When I change a:array [1..3000] to a:array [1..1] It got MEMOY LIMITE 1159Kb
Posted by Juri Krainjukov 21 Dec 2002 00:17
So, what do you think is the reason?





> > I got "Memory limit exceeded" with this program, however I can't
> > understand how can it demand more than about 30
> >
> > var
> >    n:integer;
> >    a:array[1..3000] of longint;     { 12 kb here }
> >    i,j:integer;
> >
> > procedure order(i,j:integer); { In this procedure maximum is 18
kb}
> > var                           {becuase recursion maximum depth
here}
> >     q:integer;            {is 3000}
> > begin
> >    {if i=j then
> >    begin
> >       write(a[i]);
> >       exit;
> >    end; }
> >
> >    for q:=i to j do if a[q]>a[j] then break;
> >
> >    if q<j then order(q,j-1);
> >    if q>i then order(i,q-1);
> >    write(a[j]);
> >    if j<>n then write(' ');
> >
> > end;
> >
> >
> > begin
> >    readln(n);
> >    for I:=1 to n do read(a[i]);
> >    order(1,n);
> >
> >
> > end.
> >
> >
I have such event to. I hed a:array [1..37] of boolean and got ML. I don't know whi.
Posted by I am david. Tabo. 21 Dec 2002 12:18
> So, what do you think is the reason?
>
>
>
>
>
> > > I got "Memory limit exceeded" with this program, however I
can't
> > > understand how can it demand more than about 30
> > >
> > > var
> > >    n:integer;
> > >    a:array[1..3000] of longint;     { 12 kb here }
> > >    i,j:integer;
> > >
> > > procedure order(i,j:integer); { In this procedure maximum is 18
> kb}
> > > var                           {becuase recursion maximum depth
> here}
> > >     q:integer;            {is 3000}
> > > begin
> > >    {if i=j then
> > >    begin
> > >       write(a[i]);
> > >       exit;
> > >    end; }
> > >
> > >    for q:=i to j do if a[q]>a[j] then break;
> > >
> > >    if q<j then order(q,j-1);
> > >    if q>i then order(i,q-1);
> > >    write(a[j]);
> > >    if j<>n then write(' ');
> > >
> > > end;
> > >
> > >
> > > begin
> > >    readln(n);
> > >    for I:=1 to n do read(a[i]);
> > >    order(1,n);
> > >
> > >
> > > end.
> > >
> > >
But is procedure somebody sed me that i used this array meny times. meby it is this event.
Posted by I am david. Tabo. 21 Dec 2002 18:27
> > So, what do you think is the reason?
> >
> >
> >
> >
> >
> > > > I got "Memory limit exceeded" with this program, however I
> can't
> > > > understand how can it demand more than about 30
> > > >
> > > > var
> > > >    n:integer;
> > > >    a:array[1..3000] of longint;     { 12 kb here }
> > > >    i,j:integer;
> > > >
> > > > procedure order(i,j:integer); { In this procedure maximum is
18
> > kb}
> > > > var                           {becuase recursion maximum
depth
> > here}
> > > >     q:integer;            {is 3000}
> > > > begin
> > > >    {if i=j then
> > > >    begin
> > > >       write(a[i]);
> > > >       exit;
> > > >    end; }
> > > >
> > > >    for q:=i to j do if a[q]>a[j] then break;
> > > >
> > > >    if q<j then order(q,j-1);
> > > >    if q>i then order(i,q-1);
> > > >    write(a[j]);
> > > >    if j<>n then write(' ');
> > > >
> > > > end;
> > > >
> > > >
> > > > begin
> > > >    readln(n);
> > > >    for I:=1 to n do read(a[i]);
> > > >    order(1,n);
> > > >
> > > >
> > > > end.
> > > >
> > > >
No. I don't think
Posted by Juri Krainjukov 21 Dec 2002 22:42
The 'a' array can't be used many times because it's global variable.
I don't use it as a parameter in any procedure or function.
So was in main program but......
Posted by I am david. Tabo. 22 Dec 2002 13:22
...but what?
Posted by Juri Krainjukov 22 Dec 2002 16:52
>
Re: But is procedure somebody sed me that i used this array meny times. meby it is this event.
Posted by dato 23 Dec 2002 18:17
You are right!!!!!!!
Posted by I am david. Tabo. 23 Dec 2002 19:12
>
Re: Please explain
Posted by Juri Krainjukov 25 Dec 2002 04:38
But can somebody explain me how can this procedure use the array many
times if this array is a global variable?
Either I'm very stupid or...
I don't kcnow why?
Posted by I am david. Tabo. 25 Dec 2002 10:20
> But can somebody explain me how can this procedure use the array
many
> times if this array is a global variable?
> Either I'm very stupid or...