116 - PE

All about problems in Volume I. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

116 - PE

Postby kakalata » Wed Dec 16, 2009 10:33 am

Hi all, Anyone help me check my code. I get PE with this.
Code: Select all
const
        fin='';
        fout='';
        maxn=1000 + 10;

        dy:array[1..3]of longint=(1,1,1);
        dx:array[1..3]of longint=(1,0,-1);

type
        diem = record
                x,y:longint;
        end;

var
        fi,fo:text;
        m,n,x,y:longint;
        a:array[0..maxn,0..maxn]of longint;
        trace:array[0..maxn,0..maxn]of diem;

        f:array[0..maxn,0..maxn]of int64;

        res:int64;

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

        readln(fi);
end;

procedure solve;
var
        i,j,k,u,v:longint;
begin
        for i:=1 to m do
         begin
                trace[i,n].x:=0;
                trace[i,n].y:=0;

                f[i,n]:=a[i,n];
         end;

        for j:=n - 1 downto 1 do
         for i:=1 to m do
          begin
                f[i,j]:=high(int64);

                for k:=1 to 3 do
                 begin
                        u:=i + dx[k];
                        v:=j + dy[k];

                        if u = 0 then u:=m;
                        if u > m then u:=1;

                        if f[u,v] + a[i,j] < f[i,j] then
                         begin
                                f[i,j]:=f[u,v] + a[i,j];
                                trace[i,j].x:=u;
                                trace[i,j].y:=v;
                         end
                        else
                         if f[u,v] + a[i,j] = f[i,j] then
                          if trace[i,j].x > u then
                           begin
                                trace[i,j].x:=u;
                                trace[i,j].y:=v;
                           end;
                 end;
          end;

        res:=high(int64);

        for i:=1 to m do
         if f[i,1] < res then
          begin
                res:=f[i,1];
                x:=i;
                y:=1;
          end;
end;

procedure gettrace(u,v:longint);
var
        ux,vx:longint;
begin
        write(fo,u,' ');

        ux:=trace[u,v].x;
        vx:=trace[u,v].y;
        if(ux <> 0)and(vx <> 0)then
         gettrace(ux,vx);
end;

procedure print;
begin
        gettrace(x,y);
        writeln(fo);
        writeln(fo,res);
end;

BEGIN
        assign(fi,fin);reset(fi);
        assign(fo,fout);rewrite(fo);

        while not eof(fi) do
         begin
                readfile;
                solve;
                print;
         end;

        close(fi);
        close(fo);
END.

kakalata
New poster
 
Posts: 1
Joined: Wed Dec 16, 2009 10:26 am

Re: 116 - PE

Postby chucky316 » Fri Aug 13, 2010 7:06 am

did you handle the case of one column only ???? so you won't need space after path as it will me one character only .... also make sure there is no extra spaces at the end of output ... and my AC code was with only one space separating each row number in the path more than one space got me PE
Regards
chucky316
New poster
 
Posts: 5
Joined: Mon Apr 12, 2010 11:18 am


Return to Volume I

Who is online

Users browsing this forum: No registered users and 0 guests