# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
490932 | 2021-11-29T22:05:42 Z | rainboy | Ljetopica (COI19_ljetopica) | C | 67 ms | 300 KB |
#include <stdio.h> #include <string.h> #define N 1000 #define MD 1000000007 int pp2[N + 1], vv[N + 1], ff[N + 1], gg[N + 1]; void init() { int i; pp2[0] = 1; for (i = 1; i <= N; i++) pp2[i] = pp2[i - 1] * 2 % MD; ff[0] = gg[0] = 1; for (i = 1; i <= N; i++) { vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD; ff[i] = (long long) ff[i - 1] * i % MD; gg[i] = (long long) gg[i - 1] * vv[i] % MD; } } int choose(int n, int k) { return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD; } int ans; void brute(int n, int i, int k, int x, int l, int r) { if (k == 0) { if (l <= x && x <= r) ans = (ans + x) % MD; x ^= (1 << n - 1) - 1; if (l <= x && x <= r) ans = (ans + x) % MD; return; } while (i < n - 1) brute(n, i + 1, k - 1, x ^ (1 << n - 1 - i) - 1, l, r), i++; } int main() { static char cc[N + 1], aa[N + 1], bb[N + 1]; int n, k, i, l, r, x; init(); scanf("%d%d%s%s%s", &n, &k, cc, aa, bb); if (n <= 25) { l = 0; for (i = 0; i < n; i++) l = l * 2 + aa[i] - '0'; r = 0; for (i = 0; i < n; i++) r = r * 2 + bb[i] - '0'; x = 1; for (i = 0; i < n - 1; i++) x = x * 2 + (cc[i] == 'L' ? 0 : 1); ans = 0; brute(n, 0, k, x, l, r); printf("%d\n", ans); return 0; } if (k == 0 && strcmp(aa, bb) == 0) { ans = 0; for (i = 0; i < n; i++) ans = (ans * 2 + aa[i] - '0') % MD; printf("%d\n", ans); return 0; } printf("%lld\n", (long long) (pp2[n - 1] + pp2[n] - 1) % MD * choose(n - 1, k) % MD); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 204 KB | Output is correct |
2 | Correct | 4 ms | 204 KB | Output is correct |
3 | Correct | 67 ms | 204 KB | Output is correct |
4 | Correct | 58 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 8 ms | 300 KB | Output is correct |
7 | Correct | 1 ms | 296 KB | Output is correct |
8 | Correct | 61 ms | 204 KB | Output is correct |
9 | Correct | 4 ms | 204 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 3 ms | 204 KB | Output is correct |
12 | Correct | 2 ms | 204 KB | Output is correct |
13 | Correct | 60 ms | 204 KB | Output is correct |
14 | Correct | 9 ms | 204 KB | Output is correct |
15 | Correct | 16 ms | 296 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 6 ms | 204 KB | Output is correct |
10 | Correct | 4 ms | 204 KB | Output is correct |
11 | Correct | 67 ms | 204 KB | Output is correct |
12 | Correct | 58 ms | 204 KB | Output is correct |
13 | Correct | 0 ms | 204 KB | Output is correct |
14 | Correct | 8 ms | 300 KB | Output is correct |
15 | Correct | 1 ms | 296 KB | Output is correct |
16 | Correct | 61 ms | 204 KB | Output is correct |
17 | Correct | 4 ms | 204 KB | Output is correct |
18 | Correct | 0 ms | 204 KB | Output is correct |
19 | Correct | 3 ms | 204 KB | Output is correct |
20 | Correct | 2 ms | 204 KB | Output is correct |
21 | Correct | 60 ms | 204 KB | Output is correct |
22 | Correct | 9 ms | 204 KB | Output is correct |
23 | Correct | 16 ms | 296 KB | Output is correct |
24 | Correct | 0 ms | 204 KB | Output is correct |
25 | Correct | 0 ms | 204 KB | Output is correct |
26 | Correct | 0 ms | 204 KB | Output is correct |
27 | Correct | 0 ms | 204 KB | Output is correct |
28 | Correct | 0 ms | 204 KB | Output is correct |
29 | Correct | 0 ms | 204 KB | Output is correct |
30 | Correct | 0 ms | 204 KB | Output is correct |
31 | Correct | 0 ms | 204 KB | Output is correct |
32 | Correct | 0 ms | 204 KB | Output is correct |
33 | Correct | 0 ms | 204 KB | Output is correct |
34 | Incorrect | 0 ms | 204 KB | Output isn't correct |
35 | Halted | 0 ms | 0 KB | - |