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

Strange.. OLE at #15...
Posted by Agnimon 15 Jun 2007 16:39
So anyone has the same problem as mine..?
program dafen;
const
  maxm=100;
  maxn=500;
var
  i,m,n,j,mini:integer;
  min:longint;
  f,w:array[1..maxm,1..maxn] of longint;
  g:array[1..maxm,1..maxn] of 0..3; {1:from downstair; 2:from the left; 3:from the right}

begin
  readln(m,n);
  for i:=m downto 1 do
    for j:=1 to n do
      read(w[i,j]);
  fillchar(f,sizeof(f),127);
  for i:=1 to n do f[1,i]:=w[1,i];
  for i:=2 to m do begin
    {left to right}
    f[i,1]:=f[i-1,1]+w[i,1];
    g[i,1]:=1;
    for j:=2 to n do begin
      if f[i,j]>f[i-1,j]+w[i,j] then begin
        f[i,j]:=f[i-1,j]+w[i,j];
        g[i,j]:=1;
      end;
      if f[i,j]>f[i,j-1]+w[i,j] then begin
        f[i,j]:=f[i,j-1]+w[i,j];
        g[i,j]:=2;
      end;
    end;
    {right to left}
    if f[i,n]>f[i-1,n]+w[i,n] then begin
      f[i,n]:=f[i-1,n]+w[i,n];
      g[i,n]:=1;
    end;
    for j:=n-1 downto 1 do begin
      if f[i,j]>f[i,j+1]+w[i,j] then begin
        f[i,j]:=f[i,j+1]+w[i,j];
        g[i,j]:=3;
      end;
    end;
  end;
  min:=maxlongint;
  for i:=1 to n do begin
    if f[m,i]<min then begin
      min:=f[m,i];
      mini:=i;
    end;
  end;
  i:=m;
  j:=mini;
  while not(i=1) do begin
    writeln(j);
    case g[i,j] of
    1:dec(i);
    2:dec(j);
    3:inc(j);
    end;
  end;
  writeln(j);
end.
Re: Strange.. OLE at #15...
Posted by Agnimon 15 Jun 2007 21:36
Err, the problem solved by increasing array bounds to 200*600, and change longint to double= =...
evil datas..