fork download
  1. program shhv;
  2. const
  3. nm = 50;
  4. var
  5. a: array[1..nm] of byte;
  6. t: array[1..nm] of boolean;
  7. f: array[1..nm] of longword;
  8. i, j, n: byte;
  9. s: longword;
  10. begin
  11. n := 0;
  12. while not seekeoln do
  13. begin
  14. inc(n);
  15. read(a[n]);
  16. end;
  17. fillchar(t, sizeof(t), true);
  18. s := 1; f[0] := 1;
  19. for i := 1 to n do f[i] := f[i-1] * i;
  20. for i := 1 to n do
  21. begin
  22. for j := 1 to a[i]-1 do
  23. if t[j] then s := s + f[n-i];
  24. t[a[i]] := false;
  25. end;
  26. writeln(s);
  27. readln(s);
  28. fillchar(t, sizeof(t), true);
  29. for i := 1 to n do
  30. begin
  31. for j := 1 to n do
  32. if t[j] then
  33. if (s > f[n-i]) then s := s - f[n-i] else break;
  34. a[i] := j;
  35. t[j] := false;
  36. end;
  37. for i := 1 to n do write(a[i], ' ');
  38. end.
  39.  
  40.  
  41.  
  42.  
Success #stdin #stdout 0s 280KB
stdin
1 2 3 4 5 6 7 8 9 10 11 12
238548304
stdout
1
6 12 9 4 5 1 2 8 10 7 11 3