結果

問題 No.1646 Avoid Palindrome
ユーザー trineutrontrineutron
提出日時 2021-08-13 22:06:09
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 484 ms / 3,000 ms
コード長 1,422 bytes
コンパイル時間 3,076 ms
コンパイル使用メモリ 253,992 KB
実行使用メモリ 205,112 KB
最終ジャッジ日時 2023-08-08 09:42:28
合計ジャッジ時間 19,496 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 450 ms
193,472 KB
testcase_05 AC 448 ms
193,392 KB
testcase_06 AC 434 ms
186,888 KB
testcase_07 AC 452 ms
193,420 KB
testcase_08 AC 451 ms
195,236 KB
testcase_09 AC 438 ms
185,764 KB
testcase_10 AC 442 ms
190,212 KB
testcase_11 AC 432 ms
184,988 KB
testcase_12 AC 449 ms
193,156 KB
testcase_13 AC 453 ms
195,240 KB
testcase_14 AC 449 ms
189,940 KB
testcase_15 AC 460 ms
193,420 KB
testcase_16 AC 444 ms
188,656 KB
testcase_17 AC 464 ms
196,812 KB
testcase_18 AC 453 ms
191,628 KB
testcase_19 AC 450 ms
190,472 KB
testcase_20 AC 451 ms
192,164 KB
testcase_21 AC 461 ms
196,552 KB
testcase_22 AC 444 ms
189,940 KB
testcase_23 AC 461 ms
197,600 KB
testcase_24 AC 480 ms
204,992 KB
testcase_25 AC 481 ms
205,036 KB
testcase_26 AC 483 ms
205,060 KB
testcase_27 AC 481 ms
205,108 KB
testcase_28 AC 484 ms
205,112 KB
testcase_29 AC 473 ms
205,004 KB
testcase_30 AC 470 ms
205,040 KB
testcase_31 AC 469 ms
205,000 KB
testcase_32 AC 469 ms
204,992 KB
testcase_33 AC 470 ms
204,996 KB
testcase_34 AC 479 ms
205,112 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,384 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,384 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 472 ms
205,060 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