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

Why am i getting wrong answer/(Memory Limit Exceed lately)? here is my source
Posted by Costel::icerapper@k.ro 27 Feb 2002 18:09
program timus_1029;
const
  maxk=1000000000;
  maxn=500;
  maxm=100;
type
  tcoord=record line,column:word; end;
  tart=record
             cost:longint;
             exists:boolean;
             father:tcoord;
             fee:longint;
       end;
  tm=array[1..maxm,1..maxn]of tart;
var
  a:tm;
  m,n:word;
  minlastcolumn:word;

procedure init_dat1;
begin
  fillchar(a,sizeof(a),0);
end;

procedure read_data;
var
  i,j:word;
begin
  readln(m,n);
  for i:=1 to m do
    for j:=1 to n do
      read(a[i,j].fee);
end;

procedure init_dat2;
var
  i:word;
begin
  for i:=1 to n do
    a[1,i].exists:=true;
end;

procedure art_solve;
var
  line:word;
  column:word;
begin
  for line:=2 to m do
  begin
    for column:=1 to n do
      a[line,column].cost:=maxk+1;
    for column:=1 to n do
      if a[line-1,column].exists then
        begin
          a[line,column].cost:=a[line-1,column].fee+a[line-1,column].cost;
          a[line,column].father.line:=line-1;
          a[line,column].father.column:=column;
          if (a[line,column].cost+a[line,column].fee)<=maxk then
            a[line,column].exists:=true;
        end;
    for column:=2 to n do
      if a[line,column-1].exists then
      if a[line,column].cost>(a[line,column-1].cost+a[line,column-1].fee)then
      begin
        a[line,column].cost:=a[line,column-1].cost+a[line,column-1].fee;
        a[line,column].father.line:=line;
        a[line,column].father.column:=column-1;
        if (a[line,column].cost+a[line,column].fee)<=maxk then
          a[line,column].exists:=true;
      end;
    for column:=n-1 downto 1 do
      if a[line,column+1].exists then
      if a[line,column].cost>(a[line,column+1].cost+a[line,column+1].fee)then
      begin
        a[line,column].cost:=a[line,column+1].cost+a[line,column+1].fee;
        a[line,column].father.line:=line;
        a[line,column].father.column:=column+1;
        if (a[line,column].cost+a[line,column].fee)<=maxk then
          a[line,column].exists:=true;
      end;
  end;
end;

procedure find_mway;
var
  i:word;
  value:longint;
begin
  value:=maxk+1;
  for i:=1 to n do
    if a[m,i].exists then
      if (a[m,i].cost+a[m,i].fee)<value then
      begin
        value:=a[m,i].cost+a[m,i].fee;
        minlastcolumn:=i;
      end;
end;

procedure writ_data(line,column:word);
begin
  if (line=0)or(column=0)then
    exit;
  writ_data(a[line,column].father.line,a[line,column].father.column);
  writeln(column);
end;

procedure write_sol;
begin
  writ_data(m,minlastcolumn);
end;

begin
  init_dat1;
  read_data;
  init_dat2;
  art_solve;
  find_mway;
  write_sol;
end.
longint is not big enough!!!! ... isn't it ? ...
Posted by MadPsyentist/Sam 28 Feb 2002 04:16
but fortunately , you can use Extended here
It's enough :) (-)
Posted by Miguel Angel 28 Feb 2002 05:45
anyway , to anyone who got WA , try replacing longint with extended/long double and you may get AC. it happened in my case -_-"...
Posted by MadPsyentist/Sam 28 Feb 2002 21:59