답안 #98233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98233 2019-02-21T15:43:01 Z dalgerok Mate (COCI18_mate) C++17
100 / 100
541 ms 14720 KB
#include<bits/stdc++.h>
using namespace std;


const int N = 2005, M = 26, MOD = 1e9 + 7;




string s;
int n, m, dp[N][M][M], sum[N][M];


inline void upd(int &x, int y){
    x += y;
    if(x >= MOD){
        x -= MOD;
    }
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> s;
    n = (int)s.size();
    for(auto &it : s){
        it -= 'a';
    }
    s = '#' + s;
    for(int i = 1; i <= n; i++){
        for(int j = i; j >= 2; j--){
            for(int k = 0; k < M; k++){
                upd(dp[j][k][s[i]], sum[j - 1][k]);
                upd(sum[j][s[i]], sum[j - 1][k]);
            }
        }
        upd(sum[1][s[i]], 1);
    }
    cin >> m;
    while(m--){
        int len;
        char x, y;
        cin >> len >> x >> y;
        x -= 'a';
        y -= 'a';
        cout << dp[len][x][y] << "\n";
    }
}

Compilation message

mate.cpp: In function 'int main()':
mate.cpp:32:34: warning: array subscript has type 'char' [-Wchar-subscripts]
                 upd(dp[j][k][s[i]], sum[j - 1][k]);
                                  ^
mate.cpp:33:32: warning: array subscript has type 'char' [-Wchar-subscripts]
                 upd(sum[j][s[i]], sum[j - 1][k]);
                                ^
mate.cpp:36:24: warning: array subscript has type 'char' [-Wchar-subscripts]
         upd(sum[1][s[i]], 1);
                        ^
mate.cpp:45:26: warning: array subscript has type 'char' [-Wchar-subscripts]
         cout << dp[len][x][y] << "\n";
                          ^
mate.cpp:45:29: warning: array subscript has type 'char' [-Wchar-subscripts]
         cout << dp[len][x][y] << "\n";
                             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1024 KB Output is correct
2 Correct 8 ms 640 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
4 Correct 11 ms 768 KB Output is correct
5 Correct 41 ms 2680 KB Output is correct
6 Correct 45 ms 2800 KB Output is correct
7 Correct 35 ms 2424 KB Output is correct
8 Correct 30 ms 2304 KB Output is correct
9 Correct 465 ms 14712 KB Output is correct
10 Correct 541 ms 14720 KB Output is correct