about summary refs log tree commit diff
path: root/codechef
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-07-15 19:58:48 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-07-15 19:58:48 +0700
commitbe6678fbca007e73d69c9a9c5cddb8241a987149 (patch)
treee00165734b3b3ab2ca8d47e32ef5d7868b4804c3 /codechef
parent6c0ea3cc3364733e8d8fe7625b128f817d55b2cd (diff)
downloadcp-be6678fbca007e73d69c9a9c5cddb8241a987149.tar.gz
So I gave up on a number theory one
Diffstat (limited to 'codechef')
-rwxr-xr-xcodechef/chfm.py12
-rw-r--r--codechef/cirmerge.c32
-rwxr-xr-xcodechef/mmax.py6
-rw-r--r--codechef/prtagn.c47
4 files changed, 97 insertions, 0 deletions
diff --git a/codechef/chfm.py b/codechef/chfm.py
new file mode 100755
index 0000000..99b3d99
--- /dev/null
+++ b/codechef/chfm.py
@@ -0,0 +1,12 @@
+#!/usr/bin/env python3
+for _ in range(int(input())):
+    input()
+    a = [int(i) for i in input().split()]
+    d, m = divmod(sum(a), len(a))
+    if m:
+        print('Impossible')
+        continue
+    try:
+        print(a.index(d) + 1)
+    except ValueError:
+        print('Impossible')
diff --git a/codechef/cirmerge.c b/codechef/cirmerge.c
new file mode 100644
index 0000000..678f47a
--- /dev/null
+++ b/codechef/cirmerge.c
@@ -0,0 +1,32 @@
+#include <stdio.h>
+
+int main()
+{
+	int t, n, i, j, k;
+	long long tmp, a[400][400], p[400][400] = {};
+
+	for (scanf("%d", &t); t--; printf("%lld\n", tmp)) {
+		scanf("%d", &n);
+		for (i = 0; i < n; ++i)
+			scanf("%lld", *a + i);
+
+		for (i = 1; i < n; ++i)
+			for (j = 0; j < n; ++j) {
+				p[i][j] = p[i-1][j];
+				for (k = 1; k < i; ++k) {
+					tmp = p[k-1][j] + p[i-k][(j+k)%n];
+					if (tmp < p[i][j])
+						p[i][j] = tmp;
+				}
+				p[i][j] += a[i][j] = a[i-1][j] + a[0][(i+j)%n];
+			}
+
+		long long *m = p[n-1];
+		tmp = *m;
+		for (i = 1; i < n; ++i)
+			if (m[i] < tmp)
+				tmp = m[i];
+	}
+
+	return 0;
+}
diff --git a/codechef/mmax.py b/codechef/mmax.py
new file mode 100755
index 0000000..e62fc7d
--- /dev/null
+++ b/codechef/mmax.py
@@ -0,0 +1,6 @@
+#!/usr/bin/env python3
+for _ in range(int(input())):
+    n = int(input())
+    k = int(input())
+    m = k % n
+    print(min(m * 2, (n - m) * 2, n - 1))
diff --git a/codechef/prtagn.c b/codechef/prtagn.c
new file mode 100644
index 0000000..deadb6f
--- /dev/null
+++ b/codechef/prtagn.c
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int prt(long n)
+{
+	int tmp;
+	for (tmp = n & 1; n >>= 1; tmp ^= n & 1);
+	return tmp;
+}
+
+int main()
+{
+	char t;
+	long q, x, z, *s = malloc(sizeof(long) << 17);
+
+	scanf("%hhd", &t);
+	while (t--) {
+		char *in = calloc(1 << 17, sizeof(char));
+		long e = 0, o = 0, *p = s;
+
+		scanf("%ld", &q);
+		while (q--) {
+			scanf("%ld", &x);
+			if (in[x]) {
+				printf("%ld %ld\n", e, o);
+				continue;
+			}
+
+			long *y = p;
+			while (y-- > s)
+				if ((z = x ^ *y) && !in[z]) {
+					*p++ = z;
+					in[z] = 1;
+					prt(z) ? o++ : e++;
+				}
+
+			*p++ = x;
+			in[x] = 1;
+			prt(x) ? o++ : e++;
+			printf("%ld %ld\n", e, o);
+		}
+
+		free(in);
+	}
+
+	return 0;
+}