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 1029. Ministry

WA on test14……
Posted by lonelycorn 27 Sep 2007 21:18
I got WA on test 14
does anyone who have the data?
i don't know what to do because i found some data and tested myself,finding that my program's right.
here is my program
program p1029;
const d:array[1..3,1..2]of integer=((1,0),(0,-1),(0,+1)); //from:down ,left, right
var
  i,j,k,l,m,n,ans,t,x,y:longint;
  a,f,w:array[1..500,1..500]of longint;
  sx,sy:array[0..50000]of integer;
  flag:boolean;
procedure make;
var
  i,j:longint;
begin
  for i:=1 to m do
    repeat
      flag:=false;
      for j:=1 to n do
      begin
        if (j-1>=1)and(f[i,j-1]>a[i,j-1]+f[i,j]) then
        begin
          f[i,j-1]:=f[i,j]+a[i,j-1];
          w[i,j-1]:=2;
          flag:=true;
        end;
        if (j+1<=n)and(f[i,j+1]>a[i,j+1]+f[i,j]) then
        begin
          f[i,j+1]:=a[i,j+1]+f[i,j];
          w[i,j+1]:=3;
          flag:=true;
        end;
        if (i+1<=m)and(f[i+1,j]>a[i+1,j]+f[i,j]) then
        begin
          f[i+1,j]:=f[i,j]+a[i+1,j];
          flag:=true;
          w[i+1,j]:=1;
        end;
      end;
    until not flag;
end;
procedure print(x,y:integer);
var
  x1,y1,x2,y2:integer;
begin
  inc(sx[0]);
  sx[sx[0]]:=x;
  sy[sx[0]]:=y;
  if w[x,y]<>0 then
  while true do
  begin
    x2:=sx[sx[0]];
    y2:=sy[sx[0]];
    x1:=sx[sx[0]]-d[w[x2,y2],1];
    y1:=sy[sx[0]]-d[w[x2,y2],2];
    inc(sx[0]);
    sx[sx[0]]:=x1;
    sy[sx[0]]:=y1;
    if (w[x1,y1]=0) then exit;
  end;
end;
begin
  readln(m,n);
  for i:=1 to m do
    for j:=1 to n do read(a[i,j]);
  for i:=1 to m do
    for j:=1 to n do f[i,j]:=maxlongint;
  for i:=1 to n do f[1,i]:=a[1,i];
  make;
  ans:=maxlongint;
  for i:=1 to n do if ans>f[m,i] then
  begin
    ans:=f[m,i];
    t:=i;
  end;
  fillchar(sx,sizeof(sx),0);
  print(m,t);
  for i:=sx[0] downto 1 do writeln(sy[i]);
end.
Re: WA on test14……
Posted by KAJIAIII 27 Sep 2007 21:41
I think? that it's very easy to do
this task!!!

Edited by author 27.09.2007 21:42

Edited by author 27.09.2007 21:42