ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1136. Парламент

How much memory does my program need?
Послано Juri Krainjukov 20 дек 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
Послано I am david. Tabo. 20 дек 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
Послано Juri Krainjukov 21 дек 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.
Послано I am david. Tabo. 21 дек 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.
Послано I am david. Tabo. 21 дек 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
Послано Juri Krainjukov 21 дек 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......
Послано I am david. Tabo. 22 дек 2002 13:22
...but what?
Послано Juri Krainjukov 22 дек 2002 16:52
>
Re: But is procedure somebody sed me that i used this array meny times. meby it is this event.
Послано dato 23 дек 2002 18:17
You are right!!!!!!!
Послано I am david. Tabo. 23 дек 2002 19:12
>
Re: Please explain
Послано Juri Krainjukov 25 дек 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?
Послано I am david. Tabo. 25 дек 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...