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

Help!!! I don't understand why it's wrong.
Posted by meoden 25 Feb 2002 10:37
I can't find mistakes. Is there anybody help me?

{$n+}
const
   maxm=100;
   maxn=500;
   maxx=2000000000;
var a,d:array[1..maxm,1..maxn] of longint;
    t:array[1..maxm,1..maxn] of byte;
    m,n:integer;

procedure input_data;
var i,j:integer;
begin
   readln(m,n);
   for i:=1 to m do
   begin
      for j:=1 to n do read(a[i,j]);
      readln;
   end;
end;

procedure solve;
var i,j:integer;
    ok:boolean;
begin
   for i:=1 to m do for j:=1 to n do d[i,j]:=maxx;
   for i:=1 to n do d[1,i]:=a[1,i];

   ok:=true;
   while ok do
   begin
      ok:=false;
      for i:=2 to m do
      for j:=1 to n do
      begin
         if d[i,j]-a[i,j]>d[i-1,j] then
         begin
            d[i,j]:=a[i,j]+d[i-1,j];
            t[i,j]:=1;
            ok:=true;
         end;
         if j<>n then
         if d[i,j]-a[i,j]>d[i,j+1] then
         begin
            d[i,j]:=a[i,j]+d[i,j+1];
            t[i,j]:=2;
            ok:=true;
         end;
         if j<>1 then
         if d[i,j]-a[i,j]>d[i,j-1] then
         begin
            d[i,j]:=a[i,j]+d[i,j-1];
            t[i,j]:=3;
            ok:=true;
         end;
      end;
   end;
end;

procedure output_data;
var i,j:integer;
   procedure print(i,j:integer);
   var j1:integer;
   begin
      if i>=2 then
      begin
         j1:=j;
         if t[i,j]=1 then i:=i-1
         else if t[i,j]=2 then j:=j+1
         else if t[i,j]=3 then j:=j-1;
         print(i,j);
         writeln(j1,' ');
      end
      else writeln(j,' ');
   end;
begin
   j:=1;
   for i:=2 to n do if d[m,i]<d[m,j] then j:=i;
   print(m,j);
end;

begin
   input_data;
   solve;
   output_data;
end.
Re: Help!!! I don't understand why it's wrong.
Posted by I have answers to all your questions :) 25 Feb 2002 23:48
remove extra spaces in the end of each line of output and u'll get
TLE not WA :)