| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 143948 | Linca_Robert | Mate (COCI18_mate) | C++14 | 429 ms | 26412 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
