結果

問題 No.1646 Avoid Palindrome
ユーザー ぷらぷら
提出日時 2021-08-13 21:56:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 538 ms / 3,000 ms
コード長 1,424 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 198,340 KB
実行使用メモリ 355,328 KB
最終ジャッジ日時 2024-04-26 02:52:35
合計ジャッジ時間 19,645 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 474 ms
335,232 KB
testcase_05 AC 472 ms
334,976 KB
testcase_06 AC 456 ms
323,584 KB
testcase_07 AC 469 ms
334,976 KB
testcase_08 AC 474 ms
338,176 KB
testcase_09 AC 449 ms
321,408 KB
testcase_10 AC 457 ms
329,344 KB
testcase_11 AC 448 ms
320,256 KB
testcase_12 AC 468 ms
334,208 KB
testcase_13 AC 474 ms
338,176 KB
testcase_14 AC 491 ms
328,576 KB
testcase_15 AC 497 ms
334,976 KB
testcase_16 AC 489 ms
326,528 KB
testcase_17 AC 507 ms
340,736 KB
testcase_18 AC 498 ms
331,648 KB
testcase_19 AC 492 ms
330,240 KB
testcase_20 AC 499 ms
332,544 KB
testcase_21 AC 513 ms
340,224 KB
testcase_22 AC 491 ms
328,832 KB
testcase_23 AC 516 ms
342,272 KB
testcase_24 AC 537 ms
355,200 KB
testcase_25 AC 533 ms
355,328 KB
testcase_26 AC 534 ms
355,328 KB
testcase_27 AC 536 ms
355,072 KB
testcase_28 AC 538 ms
355,328 KB
testcase_29 AC 470 ms
355,328 KB
testcase_30 AC 475 ms
355,200 KB
testcase_31 AC 473 ms
355,200 KB
testcase_32 AC 476 ms
355,072 KB
testcase_33 AC 475 ms
355,200 KB
testcase_34 AC 532 ms
355,200 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 1 ms
6,944 KB
testcase_37 AC 1 ms
6,944 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 2 ms
6,944 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 AC 475 ms
355,072 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