結果

問題 No.1646 Avoid Palindrome
ユーザー ktr216ktr216
提出日時 2021-08-13 22:49:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,352 bytes
コンパイル時間 2,013 ms
コンパイル使用メモリ 170,888 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 03:26:37
合計ジャッジ時間 90,104 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2,529 ms
6,940 KB
testcase_05 AC 2,541 ms
6,940 KB
testcase_06 AC 2,439 ms
6,940 KB
testcase_07 AC 2,541 ms
6,944 KB
testcase_08 AC 2,545 ms
6,940 KB
testcase_09 AC 2,414 ms
6,940 KB
testcase_10 AC 2,471 ms
6,944 KB
testcase_11 AC 2,408 ms
6,940 KB
testcase_12 AC 2,503 ms
6,940 KB
testcase_13 AC 2,564 ms
6,944 KB
testcase_14 AC 2,799 ms
6,940 KB
testcase_15 AC 2,862 ms
6,944 KB
testcase_16 AC 2,802 ms
6,944 KB
testcase_17 AC 2,918 ms
6,940 KB
testcase_18 AC 2,851 ms
6,940 KB
testcase_19 AC 2,834 ms
6,940 KB
testcase_20 AC 2,849 ms
6,940 KB
testcase_21 AC 2,917 ms
6,940 KB
testcase_22 AC 2,812 ms
6,940 KB
testcase_23 AC 2,921 ms
6,944 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 AC 2,477 ms
6,940 KB
testcase_30 AC 2,496 ms
6,944 KB
testcase_31 AC 2,489 ms
6,944 KB
testcase_32 AC 2,492 ms
6,940 KB
testcase_33 AC 2,482 ms
6,940 KB
testcase_34 TLE -
testcase_35 AC 2 ms
6,940 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,944 KB
testcase_41 AC 2 ms
6,944 KB
testcase_42 AC 2 ms
6,940 KB
testcase_43 AC 2,470 ms
6,940 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