fork download
  1. program results;
  2. const
  3. MAXN = 100000;
  4.  
  5. var
  6. N, i, h : LongInt;
  7. P, R, temp, count : Array[0..MAXN-1] of LongInt;
  8. correttore : char;
  9. begin
  10. {
  11.   uncomment the two following lines if you want to read/write from files
  12.   assign(input, 'input.txt'); reset(input);
  13.   assign(output, 'output.txt'); rewrite(output);
  14. }
  15.  
  16. ReadLn(N);
  17.  
  18. for i:=0 to N-1 do
  19. Read(R[i]);
  20. ReadLn();
  21.  
  22. for i := 0 to N-1 do begin P[i] := 0; temp[i]:=0; count[i]:=0; end;
  23. temp[0]:=1; count[0]:=1; h:=0;
  24. for i:=1 to N-1 do
  25. begin
  26. if R[i]=R[i-1] then count[h]:=count[h]+1
  27. else begin h:=h+1; count[h]:=count[h]+1; temp[h]:=R[i]; end;
  28. write(temp[h]);
  29.  
  30. end;
  31. writeln; writeln(h);
  32. for i:=0 to h do if temp[i]=i+1 then correttore:='F'
  33. else correttore:='J';
  34. writeln(correttore);
  35. h:=0;
  36. if correttore='J' then
  37. begin
  38. for i:=0 to N-1 do
  39. begin
  40. if R[i]=1 then P[i]:=R[i]
  41. else
  42. begin
  43. if R[i]=temp[h] then P[i]:=h+1
  44. else
  45. begin
  46. h:=h+1;
  47. if R[i]=temp[h] then P[i]:=h+1;
  48. end;
  49. end;
  50. end;
  51. end
  52. else if correttore='F' then
  53. begin
  54. for i:=0 to N-1 do
  55. begin
  56. if R[i]=1 then P[i]:=R[i]
  57. else
  58. begin
  59. if R[i]=temp[h] then P[i]:=P[i-1]
  60. else
  61. begin
  62. h:=h+1;
  63. if R[i]=temp[h] then P[i]:=i+1;
  64. end;
  65. end;
  66. end;
  67. end
  68. else
  69. for i:=0 to N-1 do P[i]:=1;
  70.  
  71. for i:=0 to N-1 do Write(P[i], ' ');
  72. WriteLn();
  73. end.
  74.  
Success #stdin #stdout 0.01s 5308KB
stdin
5
1 1 1 4 4
stdout
1144
1
J
1 1 1 2 2