結果

問題 No.1646 Avoid Palindrome
ユーザー ktr216ktr216
提出日時 2021-08-13 22:44:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,196 bytes
コンパイル時間 1,668 ms
コンパイル使用メモリ 171,660 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 19:22:19
合計ジャッジ時間 89,991 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2,561 ms
6,944 KB
testcase_05 AC 2,568 ms
6,940 KB
testcase_06 AC 2,470 ms
6,940 KB
testcase_07 AC 2,565 ms
6,940 KB
testcase_08 AC 2,586 ms
6,940 KB
testcase_09 AC 2,479 ms
6,944 KB
testcase_10 AC 2,515 ms
6,940 KB
testcase_11 AC 2,447 ms
6,940 KB
testcase_12 AC 2,563 ms
6,940 KB
testcase_13 AC 2,579 ms
6,944 KB
testcase_14 AC 2,834 ms
6,940 KB
testcase_15 AC 2,919 ms
6,944 KB
testcase_16 AC 2,811 ms
6,940 KB
testcase_17 AC 2,945 ms
6,948 KB
testcase_18 AC 2,859 ms
6,944 KB
testcase_19 AC 2,840 ms
6,944 KB
testcase_20 AC 2,855 ms
6,940 KB
testcase_21 AC 2,903 ms
6,944 KB
testcase_22 AC 2,797 ms
6,944 KB
testcase_23 AC 2,897 ms
6,940 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 AC 2,457 ms
6,940 KB
testcase_30 AC 2,468 ms
6,940 KB
testcase_31 AC 2,462 ms
6,944 KB
testcase_32 AC 2,465 ms
6,940 KB
testcase_33 AC 2,452 ms
6,944 KB
testcase_34 TLE -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 1 ms
6,944 KB
testcase_41 AC 2 ms
6,944 KB
testcase_42 AC 1 ms
6,944 KB
testcase_43 AC 2,455 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;
    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