Submission #17919427


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000030;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<int,int> P;
typedef pair<int,P> PP;

template<class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll mod(ll val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
    return val;
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

bool ng[27][27];
int dp[300010][27]; //dp[i][j] = i文字目までで文字jが最後に来る場合の数(ただしj = 26は空文字列)

int main() {
    int L;
    cin >> L;
    string S;
    cin >> S;
    int M;
    cin >> M;
    for(int i = 0;i < 27;i++) {
        for(int j = 0;j < 27;j++) {
            ng[i][j] = false;
        }
    }
    for(int i = 0;i < M;i++) {
        char A,B;
        cin >> A >> B;
        ng[A - 'A'][B - 'A'] = true;
    }
    for(int i = 0;i < 300010;i++) {
        for(int j = 0;j < 27;j++) {
            dp[i][j] = 0;
        }
    }
    dp[0][26] = 1;
    for(int i = 0;i < L;i++) {
        for(int j = 0;j <= 26;j++) {
            if(!ng[j][S.at(i) - 'A']) {
                dp[i + 1][S.at(i) - 'A'] += dp[i][j];
                dp[i + 1][S.at(i) - 'A'] %= 10000000;
            }
            if(j != S.at(i) - 'A') {
                dp[i + 1][j] += dp[i][j];
            }
        }
    }
    int ret = 0;
    for(int i = 0;i < 26;i++) {
        ret += dp[L][i];
        ret %= 10000000;
    }
    cout << ret << endl;
}

Submission Info

Submission Time
Task deciphering - 解読 (Deciphering)
User AItale
Language C++ (GCC 9.2.1)
Score 100
Code Size 2097 Byte
Status AC
Exec Time 84 ms
Memory 35452 KiB

Judge Result

Set Name Set01 Set02 Set03 Set04 Set05 Set06 Set07 Set08 Set09 Set10 Set11 Set12 Set13 Set14 Set15 Set16 Set17 Set18 Set19 Set20
Score / Max Score 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5
Status
AC × 2
AC × 3
AC × 1
AC × 1
AC × 2
AC × 1
AC × 2
AC × 1
AC × 2
AC × 2
AC × 1
AC × 2
AC × 1
AC × 2
AC × 1
AC × 2
AC × 1
AC × 2
AC × 1
AC × 2
Set Name Test Cases
Set01 01-01, 01-02
Set02 02-01, 02-02, 02-03
Set03 03-01
Set04 04-01
Set05 05-01, 05-02
Set06 06-01
Set07 07-01, 07-02
Set08 08-01
Set09 09-01, 09-02
Set10 10-01, 10-02
Set11 11-01
Set12 12-01, 12-02
Set13 13-01
Set14 14-01, 14-02
Set15 15-01
Set16 16-01, 16-02
Set17 17-01
Set18 18-01, 18-02
Set19 19-01
Set20 20-01, 20-02
Case Name Status Exec Time Memory
01-01 AC 37 ms 35036 KiB
01-02 AC 35 ms 35228 KiB
02-01 AC 34 ms 35200 KiB
02-02 AC 28 ms 35104 KiB
02-03 AC 34 ms 35128 KiB
03-01 AC 27 ms 35100 KiB
04-01 AC 31 ms 35096 KiB
05-01 AC 33 ms 35124 KiB
05-02 AC 33 ms 35212 KiB
06-01 AC 35 ms 35172 KiB
07-01 AC 33 ms 35224 KiB
07-02 AC 34 ms 35124 KiB
08-01 AC 35 ms 35248 KiB
09-01 AC 72 ms 35228 KiB
09-02 AC 65 ms 35308 KiB
10-01 AC 74 ms 35228 KiB
10-02 AC 32 ms 35180 KiB
11-01 AC 71 ms 35336 KiB
12-01 AC 71 ms 35280 KiB
12-02 AC 28 ms 35096 KiB
13-01 AC 78 ms 35328 KiB
14-01 AC 84 ms 35316 KiB
14-02 AC 78 ms 35252 KiB
15-01 AC 74 ms 35376 KiB
16-01 AC 67 ms 35448 KiB
16-02 AC 79 ms 35280 KiB
17-01 AC 73 ms 35276 KiB
18-01 AC 73 ms 35280 KiB
18-02 AC 77 ms 35448 KiB
19-01 AC 77 ms 35452 KiB
20-01 AC 66 ms 35280 KiB
20-02 AC 64 ms 35448 KiB