답안 #297542

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
297542 2020-09-11T15:49:35 Z Hehehe Mate (COCI18_mate) C++14
0 / 100
2000 ms 49716 KB
#include<bits/stdc++.h> //:3
using namespace std;
#define DIM 2010
#define MOD 1000000007


//ifstream cin ("date.in");
//ofstream cout ("date.out");
int v[DIM],c[DIM][DIM],f[DIM],dp[DIM][30][30],a[DIM][30];
char l1,l2;
string s;
int n,i,j,x,y,q,lg;
int main (){

    cin >> s;
    n = s.size();
    s = '.' + s;

    for (i=1;i<=n;i++)
        v[i] = s[i] - 'a' + 1;

    c[0][0] = 1;

    for (i=1;i<=n;i++){
        c[i][0] = 1;
        for (j=1;j<=i;j++){
            c[i][j] = c[i-1][j-1] + c[i-1][j];
            if (c[i][j] >= MOD)
                c[i][j] -= MOD;
        }}




    for (i=1;i<=n;i++)
        for (j=i+1;j<=n;j++)
            a[i][v[j]]++;

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cout << c[i][j] << ' ';
        }cout << '\n';
    }
    
    for (lg=2;lg<=n;lg++){
        for (i=lg-1;i<=n;i++){
            x = v[i];
            for (y=1;y<=26;y++){
                dp[lg][x][y] = dp[lg][x][y]+1LL*a[i][y]*c[i-1][lg-2]%MOD;
                if (dp[lg][x][y] >= MOD)
                    dp[lg][x][y] -= MOD;
            }}}


    cin >> q;
    for (;q--;){
        cin >> lg >> l1 >> l2;
        cout << dp[lg][l1-'a'+1][l2-'a'+1] << '\n';
    }


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 74 ms 768 KB Output isn't correct
2 Incorrect 55 ms 768 KB Output isn't correct
3 Incorrect 57 ms 760 KB Output isn't correct
4 Incorrect 99 ms 892 KB Output isn't correct
5 Incorrect 372 ms 3192 KB Output isn't correct
6 Incorrect 425 ms 3192 KB Output isn't correct
7 Incorrect 320 ms 2996 KB Output isn't correct
8 Incorrect 301 ms 2808 KB Output isn't correct
9 Execution timed out 2040 ms 49676 KB Time limit exceeded
10 Execution timed out 2011 ms 49716 KB Time limit exceeded