結果

問題 No.1646 Avoid Palindrome
ユーザー trineutrontrineutron
提出日時 2021-08-13 21:47:04
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,316 bytes
コンパイル時間 3,971 ms
コンパイル使用メモリ 284,692 KB
実行使用メモリ 195,456 KB
最終ジャッジ日時 2024-04-14 17:30:25
合計ジャッジ時間 41,533 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 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,146 ms
193,664 KB
testcase_05 AC 2,142 ms
193,536 KB
testcase_06 AC 2,070 ms
187,008 KB
testcase_07 AC 2,139 ms
193,664 KB
testcase_08 AC 2,153 ms
195,456 KB
testcase_09 AC 2,041 ms
185,856 KB
testcase_10 AC 2,094 ms
190,592 KB
testcase_11 AC 2,046 ms
185,216 KB
testcase_12 AC 2,151 ms
193,280 KB
testcase_13 AC 2,164 ms
195,456 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

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++)
    {
        for (int j = 0; j < 27; j++)
        {
            for (int k = 0; k < 27; k++)
            {
                if (s.at(i) == '?')
                {
                    for (int l = 0; l < 26; l++)
                    {
                        if (l == j or l == k)
                        {
                            continue;
                        }
                        dp.at(i + 1).at(k).at(l) += dp.at(i).at(j).at(k);
                    }
                }
                else
                {
                    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