blob: b1917eeb4dd2639698834de09f4f4d6e6a1ba348 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
uses clib;
var
n: int8 = 0;
i, j, c: int8;
p: array[1..20] of uint8;
b: array of boolean;
idx: uint64 = 1;
begin
while not eof(input) do
begin
inc(n);
read(p[n])
end;
setlength(b, n + 1);
for i := 1 to n do
b[i] := true;
for i := 1 to n do
begin
c := 0;
for j := 1 to n do
if j = p[i] then
break
else if b[j] then
inc(c);
idx := idx + c * factorial[n - i];
b[p[i]] := false
end;
writeln(idx)
end.
|