結果

問題 No.1646 Avoid Palindrome
ユーザー ぷらぷら
提出日時 2021-08-13 21:56:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 513 ms / 3,000 ms
コード長 1,424 bytes
コンパイル時間 2,123 ms
コンパイル使用メモリ 200,808 KB
実行使用メモリ 355,320 KB
最終ジャッジ日時 2023-08-08 09:39:27
合計ジャッジ時間 18,920 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 460 ms
335,072 KB
testcase_05 AC 451 ms
334,808 KB
testcase_06 AC 436 ms
323,508 KB
testcase_07 AC 452 ms
334,816 KB
testcase_08 AC 458 ms
337,848 KB
testcase_09 AC 432 ms
321,420 KB
testcase_10 AC 446 ms
329,312 KB
testcase_11 AC 434 ms
320,244 KB
testcase_12 AC 451 ms
334,096 KB
testcase_13 AC 457 ms
338,084 KB
testcase_14 AC 475 ms
328,316 KB
testcase_15 AC 484 ms
334,760 KB
testcase_16 AC 476 ms
326,232 KB
testcase_17 AC 493 ms
340,536 KB
testcase_18 AC 479 ms
331,500 KB
testcase_19 AC 475 ms
330,004 KB
testcase_20 AC 486 ms
332,640 KB
testcase_21 AC 494 ms
340,224 KB
testcase_22 AC 478 ms
328,620 KB
testcase_23 AC 496 ms
342,064 KB
testcase_24 AC 513 ms
355,068 KB
testcase_25 AC 513 ms
355,068 KB
testcase_26 AC 512 ms
355,092 KB
testcase_27 AC 511 ms
354,988 KB
testcase_28 AC 513 ms
355,320 KB
testcase_29 AC 451 ms
355,240 KB
testcase_30 AC 452 ms
355,244 KB
testcase_31 AC 451 ms
355,012 KB
testcase_32 AC 452 ms
354,980 KB
testcase_33 AC 453 ms
355,032 KB
testcase_34 AC 510 ms
355,000 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 1 ms
4,384 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,384 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 455 ms
355,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;
long long dp[50005][30][30];

int main() {
    int N;
    string S;
    cin >> N >> S;
    if(N == 1) {
        cout << ((S[0] == '?')?26:1) << endl;
        return 0;
    }
    for(int i = 0; i < 26; i++) {
        for(int j = 0; j < 26; j++) {
            if(S[0] != '?' && S[0]-'a' != i) {
                continue;
            }
            if(S[1] != '?' && S[1]-'a' != j) {
                continue;
            }
            if(i == j) {
                continue;
            }
            dp[2][i][j] = 1;
        }
    }
    for(int i = 2; i < N; i++) {
        vector<long long>tmp(26);
        for(int j = 0; j < 26; j++) {
            for(int k = 0; k < 26; k++) {
                tmp[k] += dp[i][j][k];
                tmp[k] %= mod;
            }
        }
        for(int j = 0; j < 26; j++) {
            for(int k = 0; k < 26; k++) {
                if(S[i] != '?' && S[i]-'a' != k) {
                    continue;
                }
                if(j == k) {
                    continue;
                }
                dp[i+1][j][k] += tmp[j]+mod-dp[i][k][j];
                dp[i+1][j][k] %= mod;
            }
        }
    }
    long long ans = 0;
    for(int i = 0; i < 26; i++) {
        for(int j = 0; j < 26; j++) {
            ans += dp[N][i][j];
            ans %= mod;
        }
    }
    cout << ans << endl;
}
0