結果

問題 No.1646 Avoid Palindrome
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-08-13 22:16:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 591 ms / 3,000 ms
コード長 752 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 82,480 KB
実行使用メモリ 76,772 KB
最終ジャッジ日時 2024-04-26 03:05:30
合計ジャッジ時間 17,719 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
60,696 KB
testcase_01 AC 42 ms
60,236 KB
testcase_02 AC 41 ms
59,572 KB
testcase_03 AC 48 ms
62,560 KB
testcase_04 AC 404 ms
76,280 KB
testcase_05 AC 408 ms
76,204 KB
testcase_06 AC 393 ms
76,128 KB
testcase_07 AC 407 ms
76,772 KB
testcase_08 AC 413 ms
76,148 KB
testcase_09 AC 391 ms
76,416 KB
testcase_10 AC 416 ms
76,220 KB
testcase_11 AC 408 ms
76,120 KB
testcase_12 AC 406 ms
76,496 KB
testcase_13 AC 408 ms
76,760 KB
testcase_14 AC 547 ms
76,304 KB
testcase_15 AC 554 ms
76,228 KB
testcase_16 AC 539 ms
76,168 KB
testcase_17 AC 563 ms
76,296 KB
testcase_18 AC 549 ms
76,292 KB
testcase_19 AC 549 ms
76,264 KB
testcase_20 AC 549 ms
76,412 KB
testcase_21 AC 565 ms
76,176 KB
testcase_22 AC 550 ms
76,520 KB
testcase_23 AC 569 ms
76,404 KB
testcase_24 AC 580 ms
76,464 KB
testcase_25 AC 591 ms
76,436 KB
testcase_26 AC 581 ms
76,292 KB
testcase_27 AC 582 ms
76,508 KB
testcase_28 AC 577 ms
76,432 KB
testcase_29 AC 320 ms
76,264 KB
testcase_30 AC 329 ms
76,148 KB
testcase_31 AC 327 ms
76,428 KB
testcase_32 AC 328 ms
76,200 KB
testcase_33 AC 331 ms
76,288 KB
testcase_34 AC 577 ms
76,160 KB
testcase_35 AC 37 ms
53,216 KB
testcase_36 AC 38 ms
53,632 KB
testcase_37 AC 44 ms
61,300 KB
testcase_38 AC 40 ms
59,176 KB
testcase_39 AC 40 ms
58,848 KB
testcase_40 AC 39 ms
58,924 KB
testcase_41 AC 41 ms
58,688 KB
testcase_42 AC 40 ms
58,488 KB
testcase_43 AC 329 ms
76,460 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