diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | codechef/binadd.c | 51 | ||||
-rwxr-xr-x | codechef/binadd.py | 9 | ||||
-rwxr-xr-x | codechef/binxor.py | 28 | ||||
-rw-r--r-- | codechef/plmu.c | 22 | ||||
-rw-r--r-- | codechef/subsplay.c | 21 | ||||
-rwxr-xr-x | codechef/watscore.py | 5 |
7 files changed, 137 insertions, 1 deletions
diff --git a/README.md b/README.md index 25b4c80..5408e6f 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,8 @@ Phiên bản các trình dịch sử dụng test: | Java | OpenJDK 11+ | | Lua | Lua 5.1+ | | Pascal | Free Pascal 2.6.4+ | -| Raku | Rakudo 2018.12+ | | Python | Python 3.5+ | +| Raku | Rakudo 2018.12+ | | Scheme | GNU Guile 2.0.11+ | SICP không chỉ dùng Guile để chạy Scheme mà còn sử dụng Racket (`#lang sicp`) diff --git a/codechef/binadd.c b/codechef/binadd.c new file mode 100644 index 0000000..8a2f56f --- /dev/null +++ b/codechef/binadd.c @@ -0,0 +1,51 @@ +#include <stdio.h> +#include <stdlib.h> + +#define SIZE (100001 * sizeof(int)) +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) + +int main() +{ + size_t t; + int *a = malloc(SIZE), *b = malloc(SIZE), c; + *a = *b = 0; + scanf("%zu", &t); + + while (t--) { + size_t lena = 1, lenb = 1; + for (scanf(" "); (c = getchar()) > 42; a[lena++] = c - 48); + for (scanf(" "); (c = getchar()) > 42; b[lenb++] = c - 48); + + size_t len = (lena > lenb) ? lena : lenb; + for (int *n = a + len, *e = a + lena, *p = b + lenb; + n-- > a; *n = (e-- > a && *e) << 1 | (p-- > b && *p)); + + int tmp = 0; + size_t result = 0, sum = 0; + for (int *n = a + len; n-- > a;) + switch (*n | tmp) { + case 1: + result = MAX(result, 1); + break; + case 3: + tmp = 4; + break; + case 4: + result = MAX(result, sum + 2); + sum = tmp = 0; + break; + case 5: + case 6: + sum++; + break; + case 7: + if (n[1] < 3) { + result = MAX(result, sum + 2); + sum = 0; + } + } + printf("%zu\n", result); + } + + return 0; +} diff --git a/codechef/binadd.py b/codechef/binadd.py new file mode 100755 index 0000000..3ab0bab --- /dev/null +++ b/codechef/binadd.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 +for t in range(int(input())): + e, p = input(), input() + a, b = int(e, 2), int(p, 2) + count = 0 + while b: + a, b = a^b, (a&b)<<1 + count += 1 + print(count) diff --git a/codechef/binxor.py b/codechef/binxor.py new file mode 100755 index 0000000..6f87d56 --- /dev/null +++ b/codechef/binxor.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +from functools import reduce +from itertools import accumulate +from typing import Iterable, Iterator + +MOD = 1_000_000_007 +LENGTH = 100_001 + + +def add(x: int, y: int) -> int: return (x + y) % MOD +def mul(x: int, y: int) -> int: return x * y % MOD + + +def khalid(iterable: Iterable[int]) -> Iterator[int]: + yield 1 + yield from iterable + + +modinv = [pow(i, MOD-2, MOD) for i in range(1, LENGTH)] +facinv = tuple(khalid(accumulate(modinv, mul))) +fac = tuple(khalid(accumulate(range(1, LENGTH), mul))) + +for t in range(int(input())): + n = int(input()) + a, b = (min(b.count(c) for c in '01') + for b in (input() for i in range(2))) + print(reduce(add, (mul(mul(fac[n], facinv[i]), facinv[n - i]) + for i in range(abs(a-b), a+b+1, 2)))) diff --git a/codechef/plmu.c b/codechef/plmu.c new file mode 100644 index 0000000..04c4b0e --- /dev/null +++ b/codechef/plmu.c @@ -0,0 +1,22 @@ +#include <stdio.h> + +int main() +{ + char t; + size_t n, tmp, zeros, twos; + + scanf("%hhd", &t); + while (t--) { + scanf("%zu", &n); + for (size_t i = zeros = twos = 0; i < n; ++i) { + scanf("%zu", &tmp); + if (!tmp) + zeros++; + else if (tmp == 2) + twos++; + } + printf("%zu\n", zeros * (zeros - 1) + twos * (twos - 1) >> 1); + } + + return 0; +} diff --git a/codechef/subsplay.c b/codechef/subsplay.c new file mode 100644 index 0000000..691a04e --- /dev/null +++ b/codechef/subsplay.c @@ -0,0 +1,21 @@ +#include <stdio.h> + +int main() +{ + int t, n; + + scanf("%d", &t); + while (t--) { + int k = 0, hope[26] = {0}; + scanf("%d ", &n); + for (int i = 0; i < n; ++i) { + int c = getchar() - 'a'; + if (hope[c] - i > k) + k = hope[c] - i; + hope[c] = n + i; + } + printf("%d\n", k); + } + + return 0; +} diff --git a/codechef/watscore.py b/codechef/watscore.py new file mode 100755 index 0000000..d45faf2 --- /dev/null +++ b/codechef/watscore.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +print(*(sum(dict(sorted((int(p), p in '12345678' and int(s)) + for p, s in (input().split() + for i in range(int(input()))))).values()) + for t in range(int(input()))), sep='\n') |