about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-01-14 20:41:09 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-01-14 20:41:09 +0700
commitce56bd193a7c8c6437443227cd3abb51134e3e7a (patch)
tree590c003d9f99e9912e0618a8c77d73ed2b481d20
parentbf538954817e568322c83030dd2fbc688a3ee13d (diff)
downloadcp-ce56bd193a7c8c6437443227cd3abb51134e3e7a.tar.gz
At least I managed to stay in top 10%
-rwxr-xr-xcodechef/dpairs.py17
-rwxr-xr-xcodechef/eartseq.py23
-rwxr-xr-xcodechef/fancy.p62
-rwxr-xr-xcodechef/hp18.py10
-rw-r--r--codechef/mgame.c23
-rw-r--r--codechef/xypizq.lisp8
-rwxr-xr-xcodechef/xypizq.p66
7 files changed, 89 insertions, 0 deletions
diff --git a/codechef/dpairs.py b/codechef/dpairs.py
new file mode 100755
index 0000000..5110410
--- /dev/null
+++ b/codechef/dpairs.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python3
+from bisect import bisect_left as bsearch
+
+input()
+X, A = zip(*sorted(enumerate(map(int, input().split())), key=lambda t: t[1]))
+Y, B = zip(*sorted(enumerate(map(int, input().split())), key=lambda t: t[1]))
+
+N, M = len(A), len(B)
+i = j = 0
+for _ in range(N + M - 1):
+    print(X[i], Y[j])
+    try:
+        if A[i + 1] < B[j + 1]: i += 1
+        else: j += 1
+    except IndexError:
+        if i + 1 < N: i += 1
+        else: j += 1
diff --git a/codechef/eartseq.py b/codechef/eartseq.py
new file mode 100755
index 0000000..bb6258b
--- /dev/null
+++ b/codechef/eartseq.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+from math import gcd
+from itertools import cycle, islice
+from sys import stdin
+
+CANDIDATES = cycle(range(2, 30000))
+
+a, b, new = 30011, 30013, {}
+coprimes, result = [a, b], [a * b]
+for _ in range(49998):
+    for i in CANDIDATES:
+        if new.get(b * i, True) and gcd(a, i) == 1 == gcd(b, i):
+            coprimes.append(i)
+            a, b = b, i
+            break
+    new[a * b] = False
+    result.append(a * b)
+
+next(stdin)
+for N in map(int, stdin):
+    N -= 1
+    print(coprimes[N] * 30011, end=' ')
+    print(*islice(result, N))
diff --git a/codechef/fancy.p6 b/codechef/fancy.p6
new file mode 100755
index 0000000..4d75e45
--- /dev/null
+++ b/codechef/fancy.p6
@@ -0,0 +1,2 @@
+#!/usr/bin/env perl6
+for ^get() { put /<<not>>/ ?? 'Real Fancy' !! 'regularly fancy' for get }
diff --git a/codechef/hp18.py b/codechef/hp18.py
new file mode 100755
index 0000000..153ec19
--- /dev/null
+++ b/codechef/hp18.py
@@ -0,0 +1,10 @@
+#!/usr/bin/env python3
+from functools import reduce
+from math import gcd
+
+for t in range(int(input())):
+    N, a, b = map(int, input().split())
+    lcm = a * b // gcd(a, b)
+    rm = map(lambda x: (x%a==0, x%lcm==0, x%b==0), map(int, input().split()))
+    Bob, both, Alice = reduce(lambda x, y: map(int.__add__, x, y), rm)
+    print('BOB' if Bob + bool(both) > Alice else 'ALICE')
diff --git a/codechef/mgame.c b/codechef/mgame.c
new file mode 100644
index 0000000..41ef005
--- /dev/null
+++ b/codechef/mgame.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#define sqr(x) ((x) * (x))
+
+int main() {
+	long long t, n, p, diff, u, v;
+	scanf("%lld", &t);
+	while(t--) {
+		scanf("%lld %lld", &n, &p);
+		if (n < 3) {
+			printf("%lld\n", p * p * p);
+			continue;
+		}
+
+		diff = p - n;
+		if (diff % 2) {
+			u = n / 2, v = diff/2;
+			printf("%lld\n", (u+v*3+2)*(u+v*3+3) + v*(v+1)*3 + 1);
+		} else {
+			printf("%lld\n", sqr(p/2 + diff + 1) + sqr(diff)*3/4);
+		}
+	}
+	return 0;
+}
diff --git a/codechef/xypizq.lisp b/codechef/xypizq.lisp
new file mode 100644
index 0000000..3d6f14c
--- /dev/null
+++ b/codechef/xypizq.lisp
@@ -0,0 +1,8 @@
+(defun xypizq (N q x y z)
+  (cond ((= q 1) (if (= x z) (/ x (1+ (* N 2))) (- 1 (xypizq N 1 z y z))))
+        ((= q 3) (xypizq N 1 z y x))
+        (t (- 1 (/ (* y 2) (1+ (* N 2)))))))
+
+(dotimes (tests (read))
+  (let ((result (xypizq (read) (read) (read) (read) (read))))
+    (format t "~a ~a~&" (numerator result) (denominator result))))
diff --git a/codechef/xypizq.p6 b/codechef/xypizq.p6
new file mode 100755
index 0000000..ff0598f
--- /dev/null
+++ b/codechef/xypizq.p6
@@ -0,0 +1,6 @@
+#!/usr/bin/env perl6
+multi xypizq($N, 1, $x, $y, $z where $x == $z) { $x / ($N * 2 + 1) }
+multi xypizq($N, 1, $x, $y, $z) { 1 - xypizq $N, 1, $z, $y, $z }
+multi xypizq($N, 3, $x, $y, $z) { xypizq $N, 1, $z, $y, $x }
+multi xypizq($N, $t, $x, $y, $z) { 1 - $y * 2 / ($N * 2 + 1) }
+xypizq(|get.words>>.Int).nude.put for ^get