답안 #141653

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
141653 2019-08-08T16:24:18 Z mariusnicoli Mate (COCI18_mate) C++14
0 / 100
2000 ms 33528 KB
/**
banana
1
2 na
**/
#include <iostream>
#include <cstring>
#include <vector>
#define MOD 1000000007
using namespace std;
char p, u, s[2002];
int R[2002][26];
int D[2002][26][26], sol[2002][26][26];
int C[2002][2002];
vector<int> poz[26];
int n, i, j, k, t, L;
int  main () {
    cin>>s+1;
    n = strlen(s+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]) % MOD;
    }


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

///    for (i=0;i<26;i++)
///        Last[i] = n+1;
    for (i=n;i>=1;i--) {
        for (j=0;j<26;j++)
            if (s[i] == j+'a') {
                R[i][j] = 1 + R[i+1][j];
///                Last[j] = i;
            }
            else {
                R[i][j] = R[i+1][j];
///                Last[j] = Last[j+1];
            }
    }
    for (i=n;i>=1;i--) {
        for (j=0;j<26;j++)
            for (k=0;k<26;k++)
                if (s[i] == j+'a')
                    D[i][j][k] = /**D[i+1][j][k] +**/ R[i+1][k];
                else
                    D[i][j][k] = D[i+1][j][k];
    }

    for (L=2;L<=n;L++)
        for (j=0;j<26;j++)
            for (t=0;t<poz[j].size();t++) {
                i=poz[j][t];
                if (i >= L-1)
                    for (k=0;k<26;k++) {
                        sol[L][j][k] += ((D[i][j][k] * C[i-1][L-2])%MOD);
                        sol[L][j][k] %= MOD;
                    }
            }


    cin>>t;
    for (;t--;) {
        cin>>L>>p>>u;
        cout<<sol[L][p-'a'][u-'a'];
    }
    return 0;
}

Compilation message

mate.cpp: In function 'int main()':
mate.cpp:18:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     cin>>s+1;
          ~^~
mate.cpp:56:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (t=0;t<poz[j].size();t++) {
                      ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 86 ms 1144 KB Output isn't correct
2 Incorrect 58 ms 1016 KB Output isn't correct
3 Incorrect 67 ms 924 KB Output isn't correct
4 Incorrect 117 ms 1116 KB Output isn't correct
5 Incorrect 416 ms 4092 KB Output isn't correct
6 Incorrect 465 ms 4168 KB Output isn't correct
7 Incorrect 353 ms 3960 KB Output isn't correct
8 Incorrect 318 ms 3704 KB Output isn't correct
9 Execution timed out 2055 ms 33428 KB Time limit exceeded
10 Execution timed out 2061 ms 33528 KB Time limit exceeded