Submission #143948

# Submission time Handle Problem Language Result Execution time Memory
143948 2019-08-15T13:29:37 Z Linca_Robert Mate (COCI18_mate) C++14
100 / 100
429 ms 26412 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(){

    scanf( "%s", 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;
            }
        }
    }

    scanf( "%d", &Q );
    for( ; Q; Q-- ){
        int x; scanf( "%d%s", &x, aux );
        printf( "%d\n", Dp[x][ aux[0] - 'a' ][ aux[1] - 'a' ] );
    }
    return 0;
}

Compilation message

mate.cpp: In function 'int main()':
mate.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf( "%s", s + 1 );
     ~~~~~^~~~~~~~~~~~~~~
mate.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf( "%d", &Q );
     ~~~~~^~~~~~~~~~~~
mate.cpp:43:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int x; scanf( "%d%s", &x, aux );
                ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 760 KB Output is correct
2 Correct 7 ms 760 KB Output is correct
3 Correct 8 ms 764 KB Output is correct
4 Correct 11 ms 760 KB Output is correct
5 Correct 42 ms 2808 KB Output is correct
6 Correct 46 ms 2936 KB Output is correct
7 Correct 38 ms 2808 KB Output is correct
8 Correct 34 ms 2680 KB Output is correct
9 Correct 429 ms 26412 KB Output is correct
10 Correct 424 ms 26324 KB Output is correct