結果

問題 No.1646 Avoid Palindrome
ユーザー MitarushiMitarushi
提出日時 2021-07-29 12:42:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,426 ms / 3,000 ms
コード長 679 bytes
コンパイル時間 564 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 82,212 KB
最終ジャッジ日時 2023-08-08 09:04:36
合計ジャッジ時間 40,340 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
76,032 KB
testcase_01 AC 76 ms
76,240 KB
testcase_02 AC 75 ms
75,808 KB
testcase_03 AC 85 ms
76,524 KB
testcase_04 AC 981 ms
80,100 KB
testcase_05 AC 1,083 ms
80,460 KB
testcase_06 AC 954 ms
80,688 KB
testcase_07 AC 1,022 ms
80,124 KB
testcase_08 AC 1,018 ms
79,976 KB
testcase_09 AC 983 ms
80,316 KB
testcase_10 AC 978 ms
80,212 KB
testcase_11 AC 944 ms
79,924 KB
testcase_12 AC 983 ms
80,100 KB
testcase_13 AC 1,115 ms
80,100 KB
testcase_14 AC 1,310 ms
81,412 KB
testcase_15 AC 1,348 ms
81,576 KB
testcase_16 AC 1,313 ms
81,900 KB
testcase_17 AC 1,343 ms
81,740 KB
testcase_18 AC 1,347 ms
82,100 KB
testcase_19 AC 1,335 ms
81,776 KB
testcase_20 AC 1,344 ms
81,492 KB
testcase_21 AC 1,350 ms
81,152 KB
testcase_22 AC 1,295 ms
81,152 KB
testcase_23 AC 1,283 ms
80,588 KB
testcase_24 AC 1,392 ms
81,220 KB
testcase_25 AC 1,384 ms
81,360 KB
testcase_26 AC 1,418 ms
82,212 KB
testcase_27 AC 1,413 ms
81,280 KB
testcase_28 AC 1,426 ms
81,360 KB
testcase_29 AC 880 ms
80,144 KB
testcase_30 AC 860 ms
80,192 KB
testcase_31 AC 861 ms
80,200 KB
testcase_32 AC 820 ms
79,520 KB
testcase_33 AC 864 ms
80,284 KB
testcase_34 AC 1,244 ms
80,632 KB
testcase_35 AC 70 ms
71,132 KB
testcase_36 AC 73 ms
75,004 KB
testcase_37 AC 78 ms
76,244 KB
testcase_38 AC 74 ms
75,304 KB
testcase_39 AC 72 ms
75,780 KB
testcase_40 AC 75 ms
76,004 KB
testcase_41 AC 75 ms
75,952 KB
testcase_42 AC 76 ms
76,100 KB
testcase_43 AC 1,040 ms
79,956 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