Submission #62382

# Submission time Handle Problem Language Result Execution time Memory
62382 2018-07-28T09:08:21 Z win11905 Mate (COCI18_mate) C++11
0 / 100
2000 ms 127484 KB
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int, int>
#define x first
#define y second

const int N = 2e3+5;
const int M = 1e9+7;

int n, m, ret[26], c[N][N];
char A[N];
vector<pii> alp[N][N];

int main() {
    scanf("%s", A), n = strlen(A);
    for_each(A, A+n, [&](char &c) { c -= 'a'; });
    for(int i = n-2; i; --i) {
        ret[A[i+1]]++;
        for(int j = 0; j < 26; ++j) if(ret[j]) alp[A[i]][j].emplace_back(i, ret[j]);
    }
    c[0][0] = 1;
    for(int i = 1; i <= n; ++i) {
        c[i][0] = 1;
        for(int j = 1; j <= n; ++j) c[i][j] = (c[i-1][j] + c[i-1][j-1]) % M;
    }
    scanf("%d", &m);
    while(m--) {
        int d; scanf("%d %s", &d, A);
        d -= 2;
        int sum = 0;
        for(pii x : alp[A[0]-'a'][A[1]-'a']) sum = (sum + 1ll * c[x.x][d] * x.y) % M;
        printf("%d\n", sum);
    }
}

Compilation message

mate.cpp: In function 'int main()':
mate.cpp:19:19: warning: array subscript has type 'char' [-Wchar-subscripts]
         ret[A[i+1]]++;
                   ^
mate.cpp:20:56: warning: array subscript has type 'char' [-Wchar-subscripts]
         for(int j = 0; j < 26; ++j) if(ret[j]) alp[A[i]][j].emplace_back(i, ret[j]);
                                                        ^
mate.cpp:16:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", A), n = strlen(A);
     ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
mate.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &m);
     ~~~~~^~~~~~~~~~
mate.cpp:29:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int d; scanf("%d %s", &d, A);
                ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 96 ms 95224 KB Output isn't correct
2 Incorrect 99 ms 95396 KB Output isn't correct
3 Incorrect 97 ms 95452 KB Output isn't correct
4 Incorrect 103 ms 95868 KB Output isn't correct
5 Incorrect 170 ms 98368 KB Output isn't correct
6 Incorrect 183 ms 99404 KB Output isn't correct
7 Incorrect 150 ms 100156 KB Output isn't correct
8 Incorrect 174 ms 100640 KB Output isn't correct
9 Execution timed out 2028 ms 123336 KB Time limit exceeded
10 Execution timed out 2058 ms 127484 KB Time limit exceeded