結果

問題 No.1646 Avoid Palindrome
ユーザー AEnAEn
提出日時 2022-12-10 15:23:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 947 ms / 3,000 ms
コード長 1,260 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 82,168 KB
実行使用メモリ 77,496 KB
最終ジャッジ日時 2024-04-22 23:51:12
合計ジャッジ時間 20,089 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
60,688 KB
testcase_01 AC 40 ms
62,424 KB
testcase_02 AC 37 ms
60,308 KB
testcase_03 AC 44 ms
64,364 KB
testcase_04 AC 478 ms
76,608 KB
testcase_05 AC 476 ms
76,500 KB
testcase_06 AC 598 ms
76,484 KB
testcase_07 AC 461 ms
77,068 KB
testcase_08 AC 469 ms
76,592 KB
testcase_09 AC 464 ms
76,784 KB
testcase_10 AC 462 ms
76,488 KB
testcase_11 AC 470 ms
76,764 KB
testcase_12 AC 470 ms
76,524 KB
testcase_13 AC 470 ms
76,632 KB
testcase_14 AC 633 ms
77,156 KB
testcase_15 AC 662 ms
77,084 KB
testcase_16 AC 651 ms
77,264 KB
testcase_17 AC 663 ms
77,024 KB
testcase_18 AC 631 ms
77,032 KB
testcase_19 AC 629 ms
77,496 KB
testcase_20 AC 647 ms
76,948 KB
testcase_21 AC 666 ms
76,944 KB
testcase_22 AC 641 ms
77,108 KB
testcase_23 AC 649 ms
76,648 KB
testcase_24 AC 696 ms
77,008 KB
testcase_25 AC 683 ms
77,004 KB
testcase_26 AC 667 ms
77,076 KB
testcase_27 AC 680 ms
77,148 KB
testcase_28 AC 683 ms
77,232 KB
testcase_29 AC 398 ms
76,608 KB
testcase_30 AC 425 ms
76,640 KB
testcase_31 AC 438 ms
76,516 KB
testcase_32 AC 432 ms
76,536 KB
testcase_33 AC 401 ms
76,508 KB
testcase_34 AC 947 ms
76,496 KB
testcase_35 AC 33 ms
52,816 KB
testcase_36 AC 31 ms
52,136 KB
testcase_37 AC 32 ms
53,808 KB
testcase_38 AC 32 ms
53,608 KB
testcase_39 AC 31 ms
52,468 KB
testcase_40 AC 34 ms
52,532 KB
testcase_41 AC 33 ms
52,648 KB
testcase_42 AC 35 ms
53,164 KB
testcase_43 AC 390 ms
76,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = input()
if N==1:
    print(26 if S[0]=='?' else 1)
    exit()

def f(s):
    return ord(s)-97
mod = 998244353
dp = [[0]*26 for _ in range(26)]
if S[0]=='?' and S[1]=='?':
    for i in range(26):
        for j in range(26):
            if i==j:continue
            dp[i][j] = 1
elif S[0]=='?':
    s = f(S[1])
    for i in range(26):
        if i==s:continue
        dp[i][s] = 1
elif S[1]=='?':
    s = f(S[0])
    for i in range(26):
        if i==s:continue
        dp[s][i] = 1
else:
    s1, s2 = f(S[0]), f(S[1])
    dp[s1][s2] = 1

for i in range(2,N):
    ndp = [[0]*26 for _ in range(26)]
    sm = [0]*26
    for j in range(26):
        for k in range(26):
            if j==k:continue
            sm[k] += dp[j][k]
            sm[k] %= mod
    if S[i]=='?':
        for j in range(26):
            for k in range(26):
                if j==k:continue
                ndp[j][k] += sm[j]-dp[k][j]
                ndp[j][k] %= mod
    else:
        s = f(S[i])
        for j in range(26):
            ndp[j][s] += sm[j]-dp[s][j]
            ndp[j][s] %= mod
    dp = ndp
res = 0
for i in range(26):
    for j in range(26):
        if i==j:continue
        res += dp[i][j]
        res %= mod
print(res)
            
        
        

0