about summary refs log tree commit diff
path: root/others/volume1/045.pas
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-13 10:29:05 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-13 10:29:05 +0700
commitac0a1ea7dabaee1b986927efb25e94a3a091fff5 (patch)
tree5765f412d59d73303c2ec981da4c4e1ef073bb99 /others/volume1/045.pas
parent36461ea5c65fcdf7169abdb39549ef53a15d4f03 (diff)
downloadcp-ac0a1ea7dabaee1b986927efb25e94a3a091fff5.tar.gz
Update others/volume1
Diffstat (limited to 'others/volume1/045.pas')
-rw-r--r--others/volume1/045.pas31
1 files changed, 31 insertions, 0 deletions
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.