結果

問題 No.1646 Avoid Palindrome
ユーザー trineutrontrineutron
提出日時 2021-08-13 22:06:09
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 454 ms / 3,000 ms
コード長 1,422 bytes
コンパイル時間 3,458 ms
コンパイル使用メモリ 284,132 KB
実行使用メモリ 205,440 KB
最終ジャッジ日時 2024-04-26 02:55:17
合計ジャッジ時間 17,587 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 397 ms
193,792 KB
testcase_05 AC 399 ms
193,664 KB
testcase_06 AC 383 ms
187,008 KB
testcase_07 AC 394 ms
193,792 KB
testcase_08 AC 401 ms
195,456 KB
testcase_09 AC 381 ms
185,984 KB
testcase_10 AC 394 ms
190,592 KB
testcase_11 AC 383 ms
185,344 KB
testcase_12 AC 393 ms
193,408 KB
testcase_13 AC 395 ms
195,456 KB
testcase_14 AC 367 ms
189,952 KB
testcase_15 AC 370 ms
193,792 KB
testcase_16 AC 363 ms
188,672 KB
testcase_17 AC 370 ms
196,992 KB
testcase_18 AC 354 ms
191,744 KB
testcase_19 AC 351 ms
190,720 KB
testcase_20 AC 356 ms
192,256 KB
testcase_21 AC 369 ms
196,736 KB
testcase_22 AC 349 ms
190,080 KB
testcase_23 AC 373 ms
197,760 KB
testcase_24 AC 401 ms
205,312 KB
testcase_25 AC 386 ms
205,184 KB
testcase_26 AC 383 ms
205,440 KB
testcase_27 AC 390 ms
205,184 KB
testcase_28 AC 394 ms
205,184 KB
testcase_29 AC 454 ms
205,312 KB
testcase_30 AC 451 ms
205,312 KB
testcase_31 AC 447 ms
205,312 KB
testcase_32 AC 446 ms
205,312 KB
testcase_33 AC 440 ms
205,312 KB
testcase_34 AC 390 ms
205,184 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 1 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 450 ms
205,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

int main()
{
    int n;
    string s;
    cin >> n >> s;

    vector dp(n + 1, vector(27, vector<mint>(27)));
    dp.at(0).at(26).at(26) = 1;
    for (int i = 0; i < n; i++)
    {
        if (s.at(i) == '?')
        {
            for (int k = 0; k < 27; k++)
            {
                mint s = 0;
                for (int j = 0; j < 27; j++)
                {
                    s += dp.at(i).at(j).at(k);
                }

                for (int l = 0; l < 26; l++)
                {
                    if (l == k)
                    {
                        continue;
                    }
                    dp.at(i + 1).at(k).at(l) += s - dp.at(i).at(l).at(k);
                }
            }
            continue;
        }

        for (int j = 0; j < 27; j++)
        {
            for (int k = 0; k < 27; k++)
            {
                int l = s.at(i) - 'a';
                if (l == j or l == k)
                {
                    continue;
                }
                dp.at(i + 1).at(k).at(l) += dp.at(i).at(j).at(k);
            }
        }
    }

    mint ans = 0;
    for (int i = 0; i < 27; i++)
    {
        for (int j = 0; j < 27; j++)
        {
            ans += dp.at(n).at(i).at(j);
        }
    }
    cout << ans.val() << endl;
    return 0;
}
0