Submission #143946

# Submission time Handle Problem Language Result Execution time Memory
143946 2019-08-15T13:25:44 Z Linca_Robert Mate (COCI18_mate) C++14
80 / 100
2000 ms 30416 KB
#include<bits/stdc++.h>
using namespace std;

const int MOD = 1e9 + 7;

int N, Q, Dp[2005][30][30], Comb[2005][2005], Cnt[2005][30];
int Sol[30][30];
char s[2205], aux[5];
int main(){

    cin >> s + 1;
    N = strlen( s + 1 );

    Comb[0][0] = 1;
    for( int i = 1; i <= N; i++ ){
        Comb[i][0] = Comb[i][i]= 1;
        for( int j = 1; j < i; j++ ){
            Comb[i][j] = Comb[i - 1][j] + Comb[i - 1][j - 1];
            if( Comb[i][j] >= MOD )
                Comb[i][j] -= MOD;
        }
    }

    for( int i = N; i >= 1; i-- ){
        for( int sg = 0; sg <= 'z' - 'a'; sg++ )
            Cnt[i][sg] += Cnt[i + 1][sg];
        if( i > 1 )
            Cnt[i - 1][ s[i] - 'a' ]++;
    }

    for( int L = 0; L <= N - 2; L++ ){
        for( int i = L + 1; i <= N; i++ ){
            for( int j = 0; j <= 'z' - 'a'; j++ ){
                Dp[L + 2][ s[i] - 'a' ][j] += ( 1LL * Comb[i - 1][L] * Cnt[i][j] % MOD );
                if( Dp[L + 2][ s[i] - 'a' ][j] >= MOD )
                    Dp[L + 2][ s[i] - 'a' ][j] -= MOD;
            }
        }
    }

    cin >> Q;
    for( ; Q; Q-- ){
        int x; cin >> x; cin >> aux;
        cout << Dp[x][ aux[0] - 'a' ][ aux[1] - 'a' ] << "\n";
    }
    return 0;
}

Compilation message

mate.cpp: In function 'int main()':
mate.cpp:11:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     cin >> s + 1;
            ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 93 ms 888 KB Output is correct
2 Correct 60 ms 888 KB Output is correct
3 Correct 70 ms 888 KB Output is correct
4 Correct 123 ms 1144 KB Output is correct
5 Correct 431 ms 3740 KB Output is correct
6 Correct 487 ms 3828 KB Output is correct
7 Correct 376 ms 3604 KB Output is correct
8 Correct 344 ms 3400 KB Output is correct
9 Execution timed out 2052 ms 30416 KB Time limit exceeded
10 Execution timed out 2031 ms 30372 KB Time limit exceeded