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 1087. The Time to Take Stones

Please Helppppp!!!!! It's still WA on test #11!
Posted by волчонок 13 Jul 2005 19:55
Here is my code on pascal:
******************************
var n,i,k,j,min:integer;
    a:array [0..10000] of 0..2;
    b:array [0..50] of integer;
    q:boolean;


Procedure init;
 Begin
  fillchar(a,sizeof(a),0);

  readln(n,k);
   read(b[1]);
   min:=b[1];

   for i:=2 to k do begin
    read(b[i]);
    if b[i]<min then min:=b[i]
   end;
   a[min]:=1;
    for i:=1 to k do a[min+b[i]]:=2;
End;


Procedure set_a;
 Begin
  q:=false;

  for j:=1 to k do
   if i-b[j]>=min then
    if a[i-b[j]]=1 then begin q:=true; break end;

   if q then a[i]:=2
        else Begin
                a[i]:=1;
                for j:=1 to k do
                 if i+b[j]<=10000 then a[i+b[j]]:=2;
             End;
End;


Procedure main;
 Begin

   For i:=min+1 to n do
    if a[i]=0 then set_a;

End;


Procedure out;
 Begin
  if a[n]=1 then write(2) else write(1);
End;


BEGIN

 init;  main;  out;

END.
********************************