結果

問題 No.1646 Avoid Palindrome
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-08-13 22:16:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 613 ms / 3,000 ms
コード長 752 bytes
コンパイル時間 1,726 ms
コンパイル使用メモリ 86,544 KB
実行使用メモリ 77,408 KB
最終ジャッジ日時 2023-08-08 09:52:30
合計ジャッジ時間 19,054 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
75,860 KB
testcase_01 AC 80 ms
75,684 KB
testcase_02 AC 79 ms
75,684 KB
testcase_03 AC 83 ms
75,972 KB
testcase_04 AC 432 ms
77,112 KB
testcase_05 AC 432 ms
77,104 KB
testcase_06 AC 415 ms
77,096 KB
testcase_07 AC 428 ms
77,176 KB
testcase_08 AC 436 ms
77,108 KB
testcase_09 AC 412 ms
77,204 KB
testcase_10 AC 438 ms
77,316 KB
testcase_11 AC 430 ms
77,044 KB
testcase_12 AC 429 ms
77,156 KB
testcase_13 AC 434 ms
77,300 KB
testcase_14 AC 577 ms
77,136 KB
testcase_15 AC 581 ms
77,140 KB
testcase_16 AC 564 ms
76,980 KB
testcase_17 AC 591 ms
77,168 KB
testcase_18 AC 579 ms
77,128 KB
testcase_19 AC 572 ms
77,244 KB
testcase_20 AC 577 ms
76,904 KB
testcase_21 AC 589 ms
77,088 KB
testcase_22 AC 573 ms
76,852 KB
testcase_23 AC 591 ms
77,148 KB
testcase_24 AC 610 ms
77,120 KB
testcase_25 AC 610 ms
76,896 KB
testcase_26 AC 611 ms
77,408 KB
testcase_27 AC 613 ms
77,164 KB
testcase_28 AC 613 ms
77,180 KB
testcase_29 AC 352 ms
77,196 KB
testcase_30 AC 352 ms
77,092 KB
testcase_31 AC 350 ms
77,076 KB
testcase_32 AC 351 ms
77,260 KB
testcase_33 AC 353 ms
77,280 KB
testcase_34 AC 608 ms
77,036 KB
testcase_35 AC 74 ms
71,064 KB
testcase_36 AC 74 ms
71,368 KB
testcase_37 AC 79 ms
75,904 KB
testcase_38 AC 78 ms
75,844 KB
testcase_39 AC 77 ms
75,748 KB
testcase_40 AC 76 ms
75,568 KB
testcase_41 AC 78 ms
75,568 KB
testcase_42 AC 79 ms
75,464 KB
testcase_43 AC 351 ms
77,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

dp[i+1][yz] = sum(dp[i][?y]) - dp[i][zy] 

"""


import itertools

N = int(input())
S = input()

dp = [0] * (27**2)
dp[-1] = 1
mod = 998244353

for i in range(N):

    dps = [0] * 27
    for j in range(27**2):
        dps[j % 27] += dp[j]
    
    ndp = [0] * (27**2)

    if S[i] == "?":
        for yz in range(27**2):
            y = yz // 27
            z = yz % 27
            if z == 26 or y == z:
                continue
            ndp[yz] = dps[y] - dp[z*27+y]
            ndp[yz] %= mod
    else:
        z = ord(S[i])-ord('a')
        for y in range(27):
            if y == z:
                continue
            ndp[27*y+z] = dps[y] - dp[z*27+y]
            ndp[27*y+z] %= mod

    dp = ndp
    
print (sum(dp) % mod)

            
0