| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 142524 | KCSC | Mate (COCI18_mate) | C++14 | 395 ms | 24568 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 <bits/stdc++.h>
using namespace std;
const int DIM = 2005;
const int SIGMA = 26;
const int MOD = 1000000007;
char str[DIM], aux[3];
int dp[DIM][SIGMA][SIGMA], cnt[DIM][SIGMA], cmb[DIM][DIM];
int main(void) {
   // freopen("mate.in", "r", stdin);
   // freopen("mate.out", "w", stdout);
    scanf("%s", str + 1);
    int n = strlen(str + 1);
    for (int i = 0; i <= n; ++i) {
        cmb[i][0] = 1;
        for (int j = 1; j <= i; ++j)
            cmb[i][j] = (cmb[i - 1][j - 1] + cmb[i - 1][j]) % MOD;
    }
    for (int i = 1; i <= n; ++i)
        for (int j = i + 1; j <= n; ++j)
            ++cnt[i][str[j] - 'a'];
    for (int i = 1; i <= n; ++i)
        for (int j = 0; j < i; ++j)
            for (int k = 0; k < 26; ++k)
                dp[j + 2][str[i] - 'a'][k] = (1LL * cmb[i - 1][j] * cnt[i][k] + dp[j + 2][str[i] - 'a'][k]) % MOD;
    int q;
    scanf("%d", &q);
    while (q--) {
        int x;
        scanf("%d %s", &x, aux + 1);
        printf("%d\n", dp[x][aux[1] - 'a'][aux[2] - 'a']);
    }
    return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
