|
|
back to boardHelp!!! 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. |
|
|