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 1126. Magnetic Storms

To Admins, why crash 1?
Posted by Vit Demidenko 8 Oct 2009 11:29
I don't understand, why crash(access violation) in test1 ??!!

uses math;
var
n,k,l,m,d,a,i,j:longint;
p:array[0..66000] of longint;

begin
assign(input,'input.txt'); reset(input);
assign(output,'output.txt'); rewrite(output);
readln(m);
n:=0;
repeat
 inc(n);
 read(p[n]);
until p[n]=-1;
dec(n);

k:=1; d:=n;

while 1 shl k<n do inc(k);

n:=1 shl k;

for l:=d+1 to n do
p[l]:=-1;


for k:=n downto 1 do
begin
p[k+n-1]:=p[k];
end;

for k:=n-1 downto 1 do
begin
p[k]:=max(p[k*2],p[k*2+1]);
end;

for k:=0 to d-m do
begin
i:=k+n; j:=k+m-1+n;
a:=-1;

while i<j do
begin
 if odd(i) then begin a:=max(a,p[i]); inc(i); end;
 if not odd(j) then begin a:=max(a,p[j]); dec(j); end;
 i:=i div 2; j:=j div 2;
end;
a:=max(a,p[i]);

writeln(a);
end;

end.



I use {$R+} on Delphi, FP, TP - nothing Crash.

Edited by author 08.10.2009 11:30
Because of input.txt/output.txt ? (-)
Posted by Sandro (USU) 8 Oct 2009 11:32
Re: Because of input.txt/output.txt ? (-)
Posted by Vit Demidenko 8 Oct 2009 11:45
Thank you. Now wa2...