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

My Solution here,I've got AC,but not very fast
Posted by Destiny 4 Nov 2002 10:37
program railway;
const
 max=1000000000;
 maxn=10000;
var
 p,dist:array[1..maxn]of longint;
 start,stop,n:integer;
 l:array[0..3]of longint;
 cost:array[1..3]of longint;
procedure init;
var
 i:integer;
 x:longint;
begin
 for i:=1 to 3 do
  read(l[i]);
 for i:=1 to 3 do
  read(cost[i]);
 readln(n);
 readln(start,stop);
 if start>stop then
  begin
   x:=start;
   start:=stop;
   stop:=x;
  end;
 dist[1]:=0;
 for i:=2 to n do
  readln(dist[i]);
end;
function get(x,y:integer):longint;
var
 i:integer;
 sum:longint;
begin
 sum:=dist[y]-dist[x];
 for i:=1 to 3 do
  if (sum>l[i-1]) and (sum<=l[i]) then
   begin
    get:=cost[i];
    exit;
   end;
end;
procedure solve;
var
 i,j:integer;
 temp:longint;
begin
 for i:=start+1 to stop do
  p[i]:=Max;
 p[start]:=0;
 for i:=start+1 to stop do
  for j:=i-1 downto start do
   begin
    if dist[i]-dist[j]>l[3] then
     break;
    temp:=get(j,i);
    if p[j]+temp<p[i] then
      p[i]:=p[j]+temp;
   end;
 writeln(p[stop]);
end;
begin
 init;
 solve;
end.
So did I.
Posted by use_c 9 Nov 2002 08:37
271903 03:35:23
9 Nov 2002  use_c 1031 C++ Accepted 1.331 sec 106K
So did I.....
Posted by aaakkk 11 Nov 2002 17:19
> 271903 03:35:23
> 9 Nov 2002  use_c 1031 C++ Accepted 1.331 sec 106K