結果

問題 No.1646 Avoid Palindrome
ユーザー MitarushiMitarushi
提出日時 2021-07-29 12:57:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,312 ms / 3,000 ms
コード長 602 bytes
コンパイル時間 449 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 82,704 KB
最終ジャッジ日時 2023-08-08 09:03:54
合計ジャッジ時間 40,704 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
76,068 KB
testcase_01 AC 80 ms
75,880 KB
testcase_02 AC 80 ms
75,716 KB
testcase_03 AC 86 ms
76,056 KB
testcase_04 AC 1,160 ms
80,580 KB
testcase_05 AC 1,191 ms
80,600 KB
testcase_06 AC 1,177 ms
80,144 KB
testcase_07 AC 1,193 ms
81,076 KB
testcase_08 AC 1,235 ms
80,236 KB
testcase_09 AC 1,139 ms
80,348 KB
testcase_10 AC 1,165 ms
80,440 KB
testcase_11 AC 1,209 ms
81,756 KB
testcase_12 AC 1,193 ms
80,780 KB
testcase_13 AC 1,238 ms
80,336 KB
testcase_14 AC 1,140 ms
82,100 KB
testcase_15 AC 1,242 ms
82,704 KB
testcase_16 AC 1,181 ms
80,488 KB
testcase_17 AC 1,243 ms
81,444 KB
testcase_18 AC 1,183 ms
80,528 KB
testcase_19 AC 1,193 ms
81,244 KB
testcase_20 AC 1,240 ms
80,460 KB
testcase_21 AC 1,256 ms
80,244 KB
testcase_22 AC 1,175 ms
80,576 KB
testcase_23 AC 1,123 ms
80,204 KB
testcase_24 AC 1,262 ms
81,080 KB
testcase_25 AC 1,279 ms
81,540 KB
testcase_26 AC 1,277 ms
81,412 KB
testcase_27 AC 1,312 ms
81,700 KB
testcase_28 AC 1,218 ms
80,768 KB
testcase_29 AC 996 ms
80,508 KB
testcase_30 AC 951 ms
81,292 KB
testcase_31 AC 971 ms
80,824 KB
testcase_32 AC 1,018 ms
80,536 KB
testcase_33 AC 962 ms
81,160 KB
testcase_34 AC 1,158 ms
79,596 KB
testcase_35 AC 77 ms
76,032 KB
testcase_36 AC 74 ms
75,016 KB
testcase_37 AC 76 ms
75,828 KB
testcase_38 AC 76 ms
76,056 KB
testcase_39 AC 76 ms
76,028 KB
testcase_40 AC 75 ms
75,776 KB
testcase_41 AC 77 ms
75,788 KB
testcase_42 AC 76 ms
75,756 KB
testcase_43 AC 986 ms
81,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

for i in s:

    if i == "?":
        i_sum = [sum(dp[j][i] for j in range(27)) for i in range(27)]
        dp2 = [[0 if i == j or j == 26 else (i_sum[i] - dp[j][i]) % mod for j in range(27)]for i in range(27)]

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

        dp2 = [[0] * 27 for _ in range(27)]
        for j in range(27):
            if j == char:
                continue

            dp2[j][char] = sum(dp[i][j] for i in range(27) if i != char) % mod

    dp = dp2

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