結果

問題 No.1646 Avoid Palindrome
ユーザー MitarushiMitarushi
提出日時 2021-07-29 12:42:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,320 ms / 3,000 ms
コード長 679 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 82,632 KB
実行使用メモリ 80,716 KB
最終ジャッジ日時 2024-04-26 02:23:55
合計ジャッジ時間 36,590 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
62,724 KB
testcase_01 AC 45 ms
61,904 KB
testcase_02 AC 43 ms
60,268 KB
testcase_03 AC 54 ms
66,352 KB
testcase_04 AC 945 ms
79,328 KB
testcase_05 AC 994 ms
79,412 KB
testcase_06 AC 901 ms
78,852 KB
testcase_07 AC 936 ms
79,368 KB
testcase_08 AC 918 ms
79,404 KB
testcase_09 AC 883 ms
79,444 KB
testcase_10 AC 905 ms
79,008 KB
testcase_11 AC 872 ms
79,076 KB
testcase_12 AC 905 ms
79,608 KB
testcase_13 AC 1,026 ms
79,268 KB
testcase_14 AC 1,195 ms
80,136 KB
testcase_15 AC 1,230 ms
80,124 KB
testcase_16 AC 1,179 ms
80,288 KB
testcase_17 AC 1,256 ms
80,716 KB
testcase_18 AC 1,222 ms
80,044 KB
testcase_19 AC 1,230 ms
80,364 KB
testcase_20 AC 1,221 ms
80,292 KB
testcase_21 AC 1,238 ms
80,268 KB
testcase_22 AC 1,280 ms
80,120 KB
testcase_23 AC 1,185 ms
79,820 KB
testcase_24 AC 1,281 ms
80,380 KB
testcase_25 AC 1,277 ms
80,256 KB
testcase_26 AC 1,320 ms
80,440 KB
testcase_27 AC 1,319 ms
80,320 KB
testcase_28 AC 1,249 ms
80,316 KB
testcase_29 AC 819 ms
78,500 KB
testcase_30 AC 807 ms
78,492 KB
testcase_31 AC 820 ms
78,392 KB
testcase_32 AC 805 ms
78,732 KB
testcase_33 AC 820 ms
78,736 KB
testcase_34 AC 1,217 ms
79,424 KB
testcase_35 AC 37 ms
53,264 KB
testcase_36 AC 42 ms
59,324 KB
testcase_37 AC 45 ms
61,004 KB
testcase_38 AC 41 ms
59,064 KB
testcase_39 AC 41 ms
59,556 KB
testcase_40 AC 42 ms
58,908 KB
testcase_41 AC 43 ms
59,768 KB
testcase_42 AC 43 ms
60,156 KB
testcase_43 AC 981 ms
78,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = input()

mod = 998244353
dp = [[0] * 27 for _ in range(27)]
dp[-1][-1] = 1

for i in s:
    dp2 = [[0] * 27 for _ in range(27)]

    if i == "?":
        for i in range(27):
            i_sum = sum(dp[j][i] for j in range(27))
            for j in range(26):
                if i == j:
                    continue

                dp2[i][j] += i_sum - dp[j][i]

    else:
        char = ord(i) - ord("a")

        for i in range(27):
            for j in range(27):
                if i == char or j == char:
                    continue
                dp2[j][char] += dp[i][j]

    dp = [[i % mod for i in j] for j in dp2]

print(sum(map(sum, dp)) % mod)
0