結果

問題 No.1646 Avoid Palindrome
ユーザー ktr216ktr216
提出日時 2021-08-13 22:48:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,352 bytes
コンパイル時間 1,764 ms
コンパイル使用メモリ 172,316 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 19:29:56
合計ジャッジ時間 90,157 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,812 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2,554 ms
6,944 KB
testcase_05 AC 2,559 ms
6,940 KB
testcase_06 AC 2,469 ms
6,944 KB
testcase_07 AC 2,551 ms
6,944 KB
testcase_08 AC 2,577 ms
6,940 KB
testcase_09 AC 2,445 ms
6,940 KB
testcase_10 AC 2,508 ms
6,940 KB
testcase_11 AC 2,437 ms
6,940 KB
testcase_12 AC 2,552 ms
6,944 KB
testcase_13 AC 2,581 ms
6,940 KB
testcase_14 AC 2,819 ms
6,940 KB
testcase_15 AC 2,869 ms
6,944 KB
testcase_16 AC 2,795 ms
6,944 KB
testcase_17 AC 2,932 ms
6,944 KB
testcase_18 AC 2,844 ms
6,940 KB
testcase_19 AC 2,828 ms
6,944 KB
testcase_20 AC 2,858 ms
6,940 KB
testcase_21 AC 2,917 ms
6,944 KB
testcase_22 AC 2,820 ms
6,940 KB
testcase_23 AC 2,932 ms
6,940 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 AC 2,487 ms
6,940 KB
testcase_30 AC 2,480 ms
6,940 KB
testcase_31 AC 2,480 ms
6,940 KB
testcase_32 AC 2,479 ms
6,940 KB
testcase_33 AC 2,473 ms
6,940 KB
testcase_34 TLE -
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 2 ms
6,940 KB
testcase_43 AC 2,482 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
using namespace std;

typedef long long ll;

int main() {
    int N;
    string S;
    cin >> N >> S;
    if (N == 1) {
        if (S == "?") {
            cout << 26 << endl;
        } else {
            cout << 1 << endl;
        }
        return 0;
    }
    vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(28, vector<ll>(28, 0)));
    ll MOD = 998244353, ans = 0;
    dp[0][26][27] = 1;
    rep(i, 0, S.size()) {
        rep(j, 0, 28) {
            rep(k, 0, 28) {
                dp[1 - i % 2][j][k] = 0;
            }
        }
        rep(j, 0, 28) {
            rep(k, 0, 28) {
                if (j == k) continue;
                rep(l, 0, 26) {
                    if (j == l || k == l) continue;
                    if (S[i] != '?' && S[i] - 'a' != l) continue;
                    dp[1 - i % 2][k][l] += dp[i % 2][j][k];
                    dp[1 - i % 2][k][l] %= MOD;
                }
            }
        }
        /*
        rep(j, 0, 28) {
            rep(k, 0, 28) {
                cout << dp[1 - i % 2][j][k] << " ";
            }
            cout << endl;
        }
        cout << endl;
        */
    }
    rep(i, 0, 26) {
        rep(j, 0, 26) {
            ans = (ans + dp[S.size() % 2][i][j]) % MOD;
        }
    }
    cout << ans << endl;
}
0