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

Why I got Wang Answer??????
Posted by qwt 11 Mar 2002 18:05
const maxn=10000;
var
  start,n,i,j,k,m:integer;
  a:array[0..maxn] of integer;

procedure over;
begin
  writeln('NO');
  halt;
end;
begin
  fillchar(a,sizeof(A),0);
  read(n,m);
  for i:=1 to m do begin
    read(j);
    inc(a[j]);
  end;
  for i:=1 to n do if a[i]>2 then over;
  if (a[0]>1)or(a[n]>1) then over;
  repeat
     start:=-1;
    if a[0]=1 then start:=0 else
      for i:=1 to n-1 do if a[i]=2 then begin start:=i;break;end;
    for i:=start+1 to n-1 do
      if a[i]=0 then begin
        a[start]:=0;
        break;
      end else
      if a[i]>=2 then over;
    if (start=n-1)and(a[n]>0) then over;
    a[start]:=0;
  until (start=n-1)or(start=-1);
  writeln('YES');
end.