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 1031. Railway Tickets

Why do I get a "WA"?
Posted by asdfz 13 Oct 2002 14:17
My Program is:
const
     maxn=10000;
var
   l1,l2,l3,f1,f2,f3:longint;
   n,i,k:integer;
   st,ed:longint;
   length,cost:array[1..maxn] of longint;
function Getcost(s:longint):longint;
         begin
         if s<=l1
            then Getcost:=f1;
         if (s>l1) and (s<=l2)
            then Getcost:=f2;
         if (s>l2) and (s<=l3)
            then Getcost:=f3;
         end;
procedure work;
          var
             i,j:integer;
             s,t:longint;
          begin
               for i:=(st+1) to ed do
                   begin
                   while (length[i]-length[k])>l3 do
                         inc(k);
                   s:=2147483647;
                   for j:=k to (i-1) do
                       begin
                       t:=cost[j]+Getcost(length[i]-length[j]);
                       if t<s
                          then s:=t;
                       end;
                   cost[i]:=s;
                   end;
          end;
begin
     readln(l1,l2,l3,f1,f2,f3);
     readln(n);
     readln(st,ed);
     for i:=2 to n do
         readln(length[i]);
     length[1]:=0;
     k:=st;
     cost[st]:=0;
     work;
     writeln(cost[ed]);
end.
I don't know why I get a "Wa".Please help me.
Sorry,I don't know why you got WA,here is my program.
Posted by gc007 13 Oct 2002 14:50
const
 inp='1031.txt';

var
 c,a:array[1..10000]of integer;
 l1,l2,l3,c1,c2,c3,n,i,x,y,j,p:integer;
 f:text;

begin
 fillchar(a,sizeof(a),120);
 assign(f,inp);
 reset(f);
 readln(f,l1,l2,l3,c1,c2,c3);
 readln(f,n);
 readln(f,x,y);
 if x>y then begin i:=x;x:=y;y:=i;end;
 a[x]:=0;
 for i:=2 to n do readln(f,c[i]);
 close(f);
 for i:=x to y-1 do
  for j:=i+1 to y do
   begin
    if c[j]-c[i]<=l1 then p:=c1;
    if (c[j]-c[i]>l1)and(c[j]-c[i]<=l2) then p:=c2;
    if (c[j]-c[i]>l2)and(c[j]-c[i]<=l3) then p:=c3;
    if (p+a[i]<a[j])and(c[j]-c[i]<=l3) then a[j]:=p+a[i];
   end;
 writeln(a[y]);
end.
I know why do you got WA.
Posted by Yang Yi 14 Oct 2002 15:37
Insert "if st>ed then begin st:=st+ed;ed:=st-ed;st:=st-ed end;" at
line 39 in your program, then you got AC.
Try this text.
Posted by Yang Yi 23 Oct 2002 15:26
3 6 8 20 30 40
7
6 2
3
7
8
13
15
23
The answer is 70. Your program print 0.
From 6 to 2 and from 2 to 6 are the same.
Re: Try this text.
Posted by asdfz 25 Oct 2002 08:19
Thanks a lot
Re: Sorry,I don't know why you got WA,here is my program.
Posted by Pasha 5 Aug 2004 19:23
Because of changing Pascal compiler Your program now is getting TLE on test #11!