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 1651. Shortest Subchain

Help!!!
Posted by Felix_Mate 24 Jun 2015 22:44
My code got WA7.
const Nmax=100500;
var
 Dp:array[1..Nmax] of longint;
 A,V:array[1..Nmax] of longint;
 N,i:longint;

BEGIN
 readln(N);
 for i:=1 to N do
 begin
  read(A[i]);
  Dp[a[i]]:=Nmax+5;
 end;

 Dp[a[n]]:=0;
 V[a[n]]:=0;
 for i:=N-1 downto 1 do
 begin
  if(Dp[a[i]]>Dp[a[i+1]]+1) then begin
   Dp[a[i]]:=Dp[a[i+1]]+1;
   V[a[i]]:=a[i+1];
  end;
 end;

 write(a[1],' ');
 i:=V[a[1]];
 while(i<>0) do begin
  write(i,' ');
  i:=V[i];
 end;
END.