# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
83352 | charlies_moo | Mate (COCI18_mate) | C++17 | 453 ms | 36816 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <cstring>
const int z = 1e9+7;
int main() {
char s[2001];
scanf("%s", s);
int n = strlen(s);
int pt[n][n];
pt[0][0] = 1;
for (int i = 1; i < n; i++) {
pt[i][0] = pt[i][i] = 1;
for (int j = 1; j < i; j++) {
pt[i][j] = (pt[i-1][j-1] + pt[i-1][j]) % z;
}
}
int c[n][26];
for (int i = 0; i < 26; i++) {
c[n-1][i] = 0;
}
for (int i = n - 2; i >= 0; i--) {
for (int j = 0; j < 26; j++) {
c[i][j] = c[i+1][j];
}
c[i][s[i+1]-'a']++;
}
int ans[26][26][n];
memset(ans, 0, sizeof(ans));
for (int i = 0; i < n; i++) {
for (int j = 0; j < 26; j++) {
for (int k = 0; k <= i; k++) {
int t = 1ll * pt[i][k] * c[i][j] % z;
ans[s[i]-'a'][j][k] = (ans[s[i]-'a'][j][k] + t) % z;
}
}
}
int q;
scanf("%d", &q);
while (q--) {
int d;
char xy[3];
scanf("%d %s", &d, xy);
printf("%d\n", ans[xy[0]-'a'][xy[1]-'a'][d-2]);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |