# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
473613 | 2021-09-15T17:21:17 Z | rainboy | Mate (COCI18_mate) | C | 562 ms | 14556 KB |
#include <stdio.h> #include <string.h> #define N 2000 #define A 26 #define MD 1000000007 int vv[N + 1], ff[N + 1], gg[N + 1]; void init() { int i; 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; } } long long choose(int n, int k) { return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD; } int main() { static char cc[N + 1]; static int kk[A], ans[A][A][N + 1]; int n, q, i, l, a, b; init(); scanf("%s%d", cc, &q), n = strlen(cc); for (i = n - 1; i >= 0; i--) { a = cc[i] - 'a'; for (b = 0; b < A; b++) for (l = 0; l <= i + 2; l++) ans[a][b][l] = (ans[a][b][l] + choose(i, l - 2) * kk[b]) % MD; kk[a]++; } while (q--) { static char s[4]; int l; scanf("%d%s", &l, s); printf("%d\n", ans[s[0] - 'a'][s[1] - 'a'][l]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 3148 KB | Output is correct |
2 | Correct | 6 ms | 2764 KB | Output is correct |
3 | Correct | 10 ms | 2892 KB | Output is correct |
4 | Correct | 15 ms | 2956 KB | Output is correct |
5 | Correct | 58 ms | 4692 KB | Output is correct |
6 | Correct | 45 ms | 4828 KB | Output is correct |
7 | Correct | 36 ms | 4676 KB | Output is correct |
8 | Correct | 35 ms | 4548 KB | Output is correct |
9 | Correct | 555 ms | 14556 KB | Output is correct |
10 | Correct | 562 ms | 14480 KB | Output is correct |