Submission #83352

# Submission time Handle Problem Language Result Execution time Memory
83352 2018-11-07T09:25:26 Z charlies_moo Mate (COCI18_mate) C++17
100 / 100
453 ms 36816 KB
#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

mate.cpp: In function 'int main()':
mate.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", s);
     ~~~~~^~~~~~~~~
mate.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &q);
     ~~~~~^~~~~~~~~~
mate.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %s", &d, xy);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 760 KB Output is correct
2 Correct 8 ms 928 KB Output is correct
3 Correct 9 ms 1148 KB Output is correct
4 Correct 12 ms 1384 KB Output is correct
5 Correct 60 ms 3604 KB Output is correct
6 Correct 66 ms 4672 KB Output is correct
7 Correct 39 ms 5460 KB Output is correct
8 Correct 37 ms 5900 KB Output is correct
9 Correct 442 ms 32676 KB Output is correct
10 Correct 453 ms 36816 KB Output is correct