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

Common Board

I always get 'Wrong Answer' on 1029, Who can help me ?????
Posted by Pham Hung Son 19 Jun 2001 10:05
const                   maxn  = 101;
                        maxm  = 501;
                        fi    = '';
                        fo    = '';
                        vc    = 1000000001;
                        hd    : array [-1..1] of  shortint
= (0,-1,0);
var                            C,S  : array
[0..maxm,0..maxn] of longint;
                               Ht   : array [1..10000] of
byte; sb: integer;
                               truoc: array
[0..maxm,0..maxn] of shortint;
                               m,n  : byte;
                               cs   : byte;
                               kq   : longint;
{------------------------------------------------}

procedure init;
begin
     fillchar(S,sizeof(S),0);
     fillchar(C,sizeof(C),0);
     fillchar(truoc,sizeof(truoc),0);
end;

{------------------------------------------------}

procedure rdt;
var       f :text;
          i,j: byte;
begin
     read(m,n);
     for i:=1 to m do
     for j:=1 to n do read(C[ i,j ]);
end;

{------------------------------------------------}

procedure KTQHD;
var       i,j: byte;
begin
     for i:=0 to m+1 do
     for j:=0 to n+1 do S[ i,j ]:= vc;
     for j:=1 to n do S[ 1,j ]:= C[ 1,j ];
end;

{------------------------------------------------}

function min( x,y: longint ): longint;
begin
     If x < y then min:= x else min:= y;
end;

{------------------------------------------------}

procedure TinhHang( i: byte );
var       j: byte;
begin
     for j:=1 to n do
     begin
          S[ i,j ]:= S[ i,j-1 ]+C[ i,j ];
          truoc[ i,j ]:= -1;
          If S[ i,j ] > S[ i-1,j ]+C[i,j] then
          begin
               S[i,j] := S[ i-1,j ]+C[i,j]; truoc[ i,j ]:=
0;
          end;

     end;
     for j:=n downto 1 do
     begin
          If S[ i,j+1 ]+C[i,j] < S[ i,j ] then
          begin
               S[ i,j ]:= S[ i,j+1 ]+C[i,j]; truoc[ i,j ]:=
1;
          end;
     end;

end;

{------------------------------------------------}

procedure TinhQHD;
var       i: byte;
begin
     for i:=2 to m do TinhHang( i );
end;

{------------------------------------------------}

procedure TinhKQ;
var       j: byte;
begin
     kq:= vc;
     for j:=1 to n do
     If kq > S[m,j] then
     begin
          kq:= S[ m,j ]; cs:= j;
     end;
end;

{------------------------------------------------}

procedure Lannguoc;
var       il,ic,jc: byte;

begin
     ic:= m; jc:= cs;
     While ic <> 0 do
     begin
          inc( sb );
          Ht[ sb ]:= jc;
          il:= ic;
          ic:= ic + hd[ truoc[ ic,jc ] ];
          jc:= jc+truoc[ il,jc ];
     end;

end;

{------------------------------------------------}

procedure mainprog;
begin
     KTQHD;
     TinhQHD;
     TinhKQ;
     LanNguoc;
end;

{------------------------------------------------}

procedure wrtout;
var       f: text;
          i: integer;
begin
     for i:=sb downto 1 do writeln(ht[i]);
end;
{------------------------------------------------}
begin
     init;
     rdt;
     mainprog;
     wrtout;
end.