답안 #145130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
145130 2019-08-18T21:14:55 Z radugheo Mate (COCI18_mate) C++14
0 / 100
1963 ms 38804 KB
#include <bits/stdc++.h>

using namespace std;

long long l, i, j, q, k, a, x, p;
long long r[2005][30], c[2005][30];
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];
        }
    }
    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];
                    }
                }
            }
        }
    }
    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:50:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (q=0; q<v[j].size(); q++){
                       ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 91 ms 1272 KB Output isn't correct
2 Incorrect 59 ms 1016 KB Output isn't correct
3 Incorrect 68 ms 1144 KB Output isn't correct
4 Incorrect 116 ms 1144 KB Output isn't correct
5 Incorrect 414 ms 4780 KB Output isn't correct
6 Incorrect 469 ms 4984 KB Output isn't correct
7 Incorrect 358 ms 4800 KB Output isn't correct
8 Incorrect 324 ms 4400 KB Output isn't correct
9 Incorrect 1929 ms 38692 KB Output isn't correct
10 Incorrect 1963 ms 38804 KB Output isn't correct