ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1145. Rope in the Labyrinth

Why CE????
Posted by Danica Porobic 23 Jun 2004 01:39
Can someone please explain to me why is this program CE? Delphi compiles it OK. Is it MLE?

type
TPok=^TElem;
TElem=record
i,j:integer;
next:TPok
end;
var
a:array[1..1000,1..1000] of char;
t,z,p:TPok;
i,j,m,n:integer;
begin
assign(input,'');
reset(input);
z:=nil;
for i:=1 to m do
begin
for j:=1 to n do
begin
if (a[i,j]='.') and (z=nil) then
begin
new(z);;
z.i:=i;
z.j:=j;
z.next:=nil;
a[i,j]:='0'
end;
end;
end;
close(input);
t:=z;
while t<>nil do
begin
i:=t^.i;
j:=t^.j;
if a[i-1,j]='.' then
begin
new(p);
p.i:=i-1;
p.j:=j;
p.next:=nil;
z.next:=p;
z:=p;
a[i-1,j]:='0'
end;
if a[i+1,j]='.' then
begin
new(p);
p.i:=i+1;
p.j:=j;
p.next:=nil;
z.next:=p;
z:=p;
a[i+1,j]:='0'
end;
if a[i,j-1]='.' then
begin
new(p);
p.i:=i;
p.j:=j-1;
p.next:=nil;
z.next:=p;
z:=p;
a[i,j-1]:='0'
end;
if a[i,j+1]='.' then
begin
new(p);
p.i:=i;
p.j:=j+1;
p.next:=nil;
z.next:=p;
z:=p;
a[i,j+1]:='0'
end;
p:=t;
t:=t^.next;
if p<>z then
dispose(p)
end;
a[z^.i,z^.j]:=chr(0);
t:=z;
while t<>nil do
begin
i:=t^.i;
j:=t^.j;
if a[i-1,j]='0' then
begin
new(p);
p.i:=i-1;
p.j:=j;
p.next:=nil;
z.next:=p;
z:=p;
a[i-1,j]:=chr(ord(a[i,j])+1)
end;
if a[i+1,j]='0' then
begin
new(p);
p.i:=i+1;
p.j:=j;
p.next:=nil;
z.next:=p;
z:=p;
a[i+1,j]:=chr(ord(a[i,j])+1)
end;
if a[i,j-1]='0' then
begin
new(p);
p.i:=i;
p.j:=j-1;
p.next:=nil;
z.next:=p;
z:=p;
a[i,j-1]:=chr(ord(a[i,j])+1)
end;
if a[i,j+1]='0' then
begin
new(p);
p.i:=i;
p.j:=j+1;
p.next:=nil;
z.next:=p;
z:=p;
a[i,j+1]:=chr(ord(a[i,j])+1)
end;
p:=t;
t:=t^.next;
if p<>z then
dispose(p)
end;
writeln(ord(a[z^.i,z^.j]))
end.
This trouble is well known (+)
Posted by Dmitry 'Diman_YES' Kovalioff 23 Jun 2004 08:05
They use strange Delphi compiler (I think it's Delphi 2.0), so you should use it too to be absolutely sure your program shouldn't receive CE. In fact there are a few main differences between Delphi 2 and Delphi 7:
- integer is 16 bit, not 32;
- dynamic arrays are not allowed to use;
- problems with dymamic lists' compiling (your problem!) - just try to compile the text with Turbo Pascal 7 and change the text in a proper way - and your will receive WA(3).

P.S. Fixed text - WA(3):

type
TPok=^TElem;
TElem=record
i,j:integer;
next:TPok
end;
var
a:array[1..1000,1..1000] of char;
t,z,p:TPok;
i,j,m,n:integer;
begin
assign(input,'');
reset(input);
z:=nil;
for i:=1 to m do
begin
for j:=1 to n do
begin
if (a[i,j]='.') and (z=nil) then
begin
new(z);;
z^.i:=i;
z^.j:=j;
z^.next:=nil;
a[i,j]:='0'
end;
end;
end;
close(input);
t:=z;
while t<>nil do
begin
i:=t^.i;
j:=t^.j;
if a[i-1,j]='.' then
begin
new(p);
p^.i:=i-1;
p^.j:=j;
p^.next:=nil;
z^.next:=p;
z:=p;
a[i-1,j]:='0'
end;
if a[i+1,j]='.' then
begin
new(p);
p^.i:=i+1;
p^.j:=j;
p^.next:=nil;
z^.next:=p;
z:=p;
a[i+1,j]:='0'
end;
if a[i,j-1]='.' then
begin
new(p);
p^.i:=i;
p^.j:=j-1;
p^.next:=nil;
z^.next:=p;
z:=p;
a[i,j-1]:='0'
end;
if a[i,j+1]='.' then
begin
new(p);
p^.i:=i;
p^.j:=j+1;
p^.next:=nil;
z^.next:=p;
z:=p;
a[i,j+1]:='0'
end;
p:=t;
t:=t^.next;
if p<>z then
dispose(p)
end;
a[z^.i,z^.j]:=chr(0);
t:=z;
while t<>nil do
begin
i:=t^.i;
j:=t^.j;
if a[i-1,j]='0' then
begin
new(p);
p^.i:=i-1;
p^.j:=j;
p^.next:=nil;
z^.next:=p;
z:=p;
a[i-1,j]:=chr(ord(a[i,j])+1)
end;
if a[i+1,j]='0' then
begin
new(p);
p^.i:=i+1;
p^.j:=j;
p^.next:=nil;
z^.next:=p;
z:=p;
a[i+1,j]:=chr(ord(a[i,j])+1)
end;
if a[i,j-1]='0' then
begin
new(p);
p^.i:=i;
p^.j:=j-1;
p^.next:=nil;
z^.next:=p;
z:=p;
a[i,j-1]:=chr(ord(a[i,j])+1)
end;
if a[i,j+1]='0' then
begin
new(p);
p^.i:=i;
p^.j:=j+1;
p^.next:=nil;
z^.next:=p;
z:=p;
a[i,j+1]:=chr(ord(a[i,j])+1)
end;
p:=t;
t:=t^.next;
if p<>z then
dispose(p)
end;
writeln(ord(a[z^.i,z^.j]))
end.
Re: This trouble is well known (+)
Posted by Vladimir Yakovlev (USU) 23 Jun 2004 12:51
Dmitry 'Diman_YES' Kovalioff wrote 23 June 2004 08:05
They use strange Delphi compiler (I think it's Delphi 2.0), so you should use it too to be absolutely sure your program shouldn't receive CE. In fact there are a few main differences between Delphi 2 and Delphi 7:
- integer is 16 bit, not 32;
- dynamic arrays are not allowed to use;
- problems with dymamic lists' compiling
Compiler is FreePascal. See http://www.freepascal.org for detailed documentation.
Main features:
- 8-bit shortint and byte
- 16-bit smallint and word
- 32-bit integer, longint and longword
- 64-bit int64
- 255-byte strings by default
- long Delphi strings if use {\$H+} directive
- dynamic arrays are not allowed
- result variable work like in Delphi
- more strict syntax than in Delphi
Re: This trouble is well known (+)
Posted by Danica Porobic 23 Jun 2004 16:26
Thanks very much
At last it is clear (+)
Posted by Dmitry 'Diman_YES' Kovalioff 23 Jun 2004 18:06
BTW, why the information about compilers is not mentioned on this site?