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 1134. Cards

Can anybody find a mistake here ??? PLEASE !!!
Posted by uuuuuuuu 23 Jun 2002 23:31
It works correctly on my tests but I always get WA ?!
var
n,m:0..1000;
a:array[1..1000,1..3]of 0..1000;
i,k,z:integer;
begin
readln(n,m);
if (m>n)or (m=0)then
begin
writeln('NO');
halt;
end;
for i:=1 to (n+1) do
begin
a[i,1]:=i-1;
a[i,2]:=i;
end;
z:=n;
for i:=1 to m do
begin
read(k);
if (k<0)or (k>z)then
begin
writeln('NO');
halt;
end;
        if (k<>0)and(k<>z) then
        begin
             if (a[k,3]=0)or(a[k+1,3]=0) then
                         begin
                         a[k,3]:=i;
                         if a[k+1,3]=0 then a[k+1,3]:=i
                         end
        else
                        begin
                        n:=a[k,3];

                        if (a[k-1,3]=n)or(a[k+1,3]=n) then a[k,3]:=i
                                                      else

                                                      begin

                                                      writeln('NO');
                                                      halt;

                                                      end;
                        end;
        end
else if k=0 then
begin
n:=a[1,3];
      if n=0 then a[1,3]:=i
      else
      begin
      if a[2,3]=n then a[1,3]:=i
                  else
                  begin
                  writeln('NO');
                  halt;
                  end;
      end;
end
else if k=z then
     begin
     n:=a[z,3];
     if n=0 then a[z,3]:=i
      else
      begin
      if a[z-1,3]=n then a[z,3]:=i
                  else
                  begin
                  writeln('NO');
                  halt;
                  end;
      end;
     end;
end;
writeln('YES');
end.