could someone tell me why do I get Memory Limit with this solution?
maybe I am wrong but I think it shoudn't use more then 500k of memory.
type nodep=^node;
node=record
item:array[0..5]of longint;
link:nodep;
end;
var a:array[1..1000]of nodep;
p:nodep;
i,n,stiva,elem:longint;
code:integer;
s:string;
begin
for i:=1 to 1000 do
a[i]:=nil;
readln(n);
for i:=1 to n do
begin
readln(s);
if copy(s,1,4)='PUSH' then
begin
delete(s,5,1);
val(copy(s,5,pos(' ',s)-5),stiva,code);
val(copy(s,pos(' ',s)+1,length(s)-pos(' ',s)),elem,code);
if a[stiva]=nil then
begin
new(p);
p^.link:=nil;
p^.item[0]:=1;
p^.item[1]:=elem;
a[stiva]:=p;
end
else
if a[stiva]^.item[0]<>5 then
begin
inc(a[stiva]^.item[0]);
a[stiva]^.item[a[stiva]^.item[0]]:=elem;
end
else
begin
new(p);
p^.link:=a[stiva];
p^.item[0]:=1;
p^.item[1]:=elem;
a[stiva]:=p;
end;
end
else
begin
delete(s,4,1);
val(copy(s,4,length(s)-4+1),stiva,code);
writeln(a[stiva]^.item[a[stiva]^.item[0]]);
dec(a[stiva]^.item[0]);
if a[stiva]^.item[0]=0 then
begin
p:=a[stiva];
a[stiva]:=a[stiva]^.link;
dispose(p);
end;
end;
end;
end.