From ac0a1ea7dabaee1b986927efb25e94a3a091fff5 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Mon, 13 Feb 2017 10:29:05 +0700 Subject: Update others/volume1 --- others/volume1/045.pas | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 others/volume1/045.pas (limited to 'others/volume1/045.pas') diff --git a/others/volume1/045.pas b/others/volume1/045.pas new file mode 100644 index 0000000..eca1c9d --- /dev/null +++ b/others/volume1/045.pas @@ -0,0 +1,31 @@ +uses cmath; + +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. -- cgit 1.4.1