From 4b8df7227736b7c41af56e053d40decc309fe7f9 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Mon, 16 Sep 2019 20:32:51 +0700 Subject: Recovery (2010) --- codechef/chefinsq.py | 15 +++++++++++++++ codechef/fibeasy.c | 23 +++++++++++++++++++++++ codechef/gdsub.py | 18 ++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100755 codechef/chefinsq.py create mode 100644 codechef/fibeasy.c create mode 100755 codechef/gdsub.py diff --git a/codechef/chefinsq.py b/codechef/chefinsq.py new file mode 100755 index 0000000..04fd5ef --- /dev/null +++ b/codechef/chefinsq.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +from bisect import bisect_left, bisect_right +from functools import reduce +from math import factorial + + +def c(n, r): + return reduce(int.__mul__, range(n, n - r, -1), 1) // factorial(r) + + +for t in range(int(input())): + n, k = map(int, input().split()) + a = sorted(map(int, input().split())) + l, r = bisect_left(a, a[k - 1]), bisect_right(a, a[k - 1]) + print(c(r - l, min(k - l, r - k))) diff --git a/codechef/fibeasy.c b/codechef/fibeasy.c new file mode 100644 index 0000000..d5309a5 --- /dev/null +++ b/codechef/fibeasy.c @@ -0,0 +1,23 @@ +#include + +const char LAST[] = "0923"; + +int main() +{ + int t, c; + long n; + + scanf("%d", &t); + while (t--) { + scanf("%ld", &n); + if (n == 2 || n == 3) { + puts("1"); + continue; + } + + for (c = 0; n >>= 1; c++); + printf("%c\n", LAST[c % 4]); + } + + return 0; +} diff --git a/codechef/gdsub.py b/codechef/gdsub.py new file mode 100755 index 0000000..56c6a84 --- /dev/null +++ b/codechef/gdsub.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +from collections import Counter +from functools import reduce + +def mod(n): return n % 1_000_000_007 + +def cha1n(iterable): + yield 1 + yield from iterable + +n, k = map(int, input().split()) +counts = tuple(Counter(map(int, input().split())).values()) +if len(counts) <= k: + print(reduce(lambda x, y: mod(x * (y+1)), counts, 1)) +else: + s = [0] * k + for c in counts: s = [mod(x + y*c) for x, y in zip(s, cha1n(s))] + print(mod(sum(s, 1))) -- cgit 1.4.1