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 1005. Stone Pile

WHY WA1?!! A have AC this task in another site
Posted by Kirin Vladislav 17 Jan 2007 13:31
I have AC this code in another site:
http://www.olymp.vinnica.ua/alltask/task.shtml?coins
But here a have WA1. Wats wrong in my code?

program Stone_pile;
const size=20;
var a:array[1..20]of longint;
    c:array[0..size] of shortint;
    i,g1,g2,raz,j,z,kol,n:longint;

procedure ReadFile;
begin
   { assign(input,'in.txt');
     reset(input);}
     read(n);
     for i:=1 to n-1 do readln(a[size-i+1]);
     readln(a[1]);
     fillchar(c,sizeof(c),0);
     kol:=1;
     for i:=1 to n-1 do kol:=kol*2;
     dec(kol);
     raz:=MaxLongint;
end;

begin
     ReadFile;
     for z:=1 to kol+1 do
     begin
          g1:=a[1];
          g2:=0;
          for j:=size downto size-n+2 do
              if c[j]=0 then inc(g1,a[j])
              else inc(g2,a[j]);
          if abs(g1-g2)<raz then raz:=abs(g1-g2);

          inc(c[size]);
          for j:=size downto size-n+2 do if c[j]>1 then
          begin
               inc(c[j-1],c[j] div 2);
               c[j]:=c[j] mod 2;
          end;
      end;

     writeln(raz);
end.