Submission #142524

# Submission time Handle Problem Language Result Execution time Memory
142524 2019-08-09T11:06:11 Z KCSC Mate (COCI18_mate) C++14
100 / 100
395 ms 24568 KB
#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

mate.cpp: In function 'int main()':
mate.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", str + 1);
     ~~~~~^~~~~~~~~~~~~~~
mate.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &q);
     ~~~~~^~~~~~~~~~
mate.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %s", &x, aux + 1);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 760 KB Output is correct
2 Correct 7 ms 732 KB Output is correct
3 Correct 8 ms 760 KB Output is correct
4 Correct 12 ms 760 KB Output is correct
5 Correct 43 ms 2680 KB Output is correct
6 Correct 46 ms 2680 KB Output is correct
7 Correct 36 ms 2552 KB Output is correct
8 Correct 33 ms 2424 KB Output is correct
9 Correct 395 ms 24568 KB Output is correct
10 Correct 381 ms 24556 KB Output is correct