답안 #145135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
145135 2019-08-18T21:23:46 Z radugheo Mate (COCI18_mate) C++14
80 / 100
2000 ms 56696 KB
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

long long l, i, j, q, k, a, x, p;
long long r[2005][30], c[2005][2005];
long long d[2005][30][30], sol[2005][30][30];

char y, z, s[2005];

vector <long long> v[30];

int main(){
    cin >> (s + 1);
    l = strlen(s+1);
    c[0][0] = 1;
    for (i=1; i<=l; 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<=l; i++){
        v[s[i] - 'a'].push_back(i);
    }
    for (i=l; i>=1; i--){
        for (j=0; j<26; j++){
            if (s[i] == j + 'a'){
                r[i][j] = 1 + r[i+1][j];
            }
            else{
                r[i][j] = r[i+1][j];
            }
        }
    }
    for (i=l; i>=1; i--){
        for (j=0; j<26; j++){
            for (q=0; q<26; q++){
                if (s[i] == j + 'a'){
                    d[i][j][q] = r[i+1][q];
                }
                else{
                    d[i][j][q] = d[i+1][j][q];
                }
            }
        }
    }
    for (i=2; i<=l; i++){
        for (j=0; j<26; j++){
            for (q=0; q<v[j].size(); q++){
                p = v[j][q];
                if (p >= i - 1){
                    for (k=0; k<26; k++){
                        sol[i][j][k] += ((d[p][j][k] * c[p-1][i-2])%MOD);
                        if (sol[i][j][k] >= MOD)
                            sol[i][j][k] -= MOD;
                    }
                }
            }
        }
    }
    cin >> a;
    for (i=1; i<=a; i++){
        cin >> x >> y >> z;
        cout << sol[x][y-'a'][z-'a'] << "\n";
    }
    return 0;
}

Compilation message

mate.cpp: In function 'int main()':
mate.cpp:53:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (q=0; q<v[j].size(); q++){
                       ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 1272 KB Output is correct
2 Correct 59 ms 1272 KB Output is correct
3 Correct 68 ms 1144 KB Output is correct
4 Correct 115 ms 1372 KB Output is correct
5 Correct 415 ms 5136 KB Output is correct
6 Correct 466 ms 5240 KB Output is correct
7 Correct 358 ms 5164 KB Output is correct
8 Correct 326 ms 4876 KB Output is correct
9 Execution timed out 2041 ms 56428 KB Time limit exceeded
10 Execution timed out 2071 ms 56696 KB Time limit exceeded