結果

問題 No.1646 Avoid Palindrome
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-08-13 22:26:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 663 ms / 3,000 ms
コード長 1,504 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 76,800 KB
最終ジャッジ日時 2024-04-26 03:11:03
合計ジャッジ時間 19,869 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,248 KB
testcase_01 AC 45 ms
59,776 KB
testcase_02 AC 45 ms
60,160 KB
testcase_03 AC 46 ms
60,160 KB
testcase_04 AC 498 ms
76,160 KB
testcase_05 AC 498 ms
76,120 KB
testcase_06 AC 483 ms
76,416 KB
testcase_07 AC 500 ms
76,416 KB
testcase_08 AC 481 ms
76,288 KB
testcase_09 AC 468 ms
76,160 KB
testcase_10 AC 492 ms
76,492 KB
testcase_11 AC 488 ms
76,288 KB
testcase_12 AC 510 ms
76,416 KB
testcase_13 AC 505 ms
76,288 KB
testcase_14 AC 573 ms
76,544 KB
testcase_15 AC 586 ms
76,416 KB
testcase_16 AC 583 ms
76,416 KB
testcase_17 AC 590 ms
76,640 KB
testcase_18 AC 581 ms
76,396 KB
testcase_19 AC 576 ms
76,800 KB
testcase_20 AC 580 ms
76,620 KB
testcase_21 AC 608 ms
76,672 KB
testcase_22 AC 578 ms
76,560 KB
testcase_23 AC 587 ms
76,132 KB
testcase_24 AC 623 ms
76,528 KB
testcase_25 AC 616 ms
76,492 KB
testcase_26 AC 612 ms
76,460 KB
testcase_27 AC 616 ms
76,544 KB
testcase_28 AC 614 ms
76,364 KB
testcase_29 AC 636 ms
76,288 KB
testcase_30 AC 440 ms
76,416 KB
testcase_31 AC 444 ms
76,336 KB
testcase_32 AC 438 ms
76,308 KB
testcase_33 AC 446 ms
76,160 KB
testcase_34 AC 648 ms
76,128 KB
testcase_35 AC 38 ms
52,480 KB
testcase_36 AC 40 ms
52,096 KB
testcase_37 AC 38 ms
52,992 KB
testcase_38 AC 38 ms
52,352 KB
testcase_39 AC 38 ms
52,224 KB
testcase_40 AC 38 ms
52,608 KB
testcase_41 AC 39 ms
52,736 KB
testcase_42 AC 40 ms
52,864 KB
testcase_43 AC 663 ms
76,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
S = input()
mod = 998244353
dp = [0]*(26**2)
if len(S) == 1:
    if S == "?":
        ans = 26
    else:
        ans = 1
    print(ans)
    exit()

if S[0] == "?":
    if S[1] == "?":
        for i in range(26):
            for j in range(26):
                if i == j:
                    continue
                dp[i*26+j] += 1
    else:
        c = ord(S[1])-ord("a")
        for i in range(26):
            if i == c:
                continue
            dp[i*26+c] += 1
else:
    c = ord(S[0])-ord("a")
    if S[1] == "?":
        for j in range(26):
            if c == j:
                continue
            dp[c*26+j] += 1
    else:
        c2 = ord(S[1])-ord("a")
        if c != c2:
            dp[c*26+c2] += 1
base = [0]*26
for s in S[2:]:
    nbase = [0]*26
    ndp = [0]*(26**2)
    if s == "?":
        for i in range(26**2):
            x,y = divmod(i,26)
            dp[i] += base[x]
            nbase[y] += dp[i]
            nbase[y] %= mod
            ndp[y*26+y] -= dp[i]
            ndp[y*26+y] %= mod
            ndp[y*26+x] -= dp[i]
            ndp[y*26+x] %= mod

    else:
        c = ord(s)-ord("a")
        for i in range(26**2):
            x,y = divmod(i,26)
            dp[i] += base[x]
            if x == c or y == c:
                continue
            ndp[y*26+c] += dp[i]
            ndp[y*26+c] %= mod
    dp = ndp
    base = nbase
ans = 0
for i in range(26):
    for j in range(26):
        ans += dp[i*26+j]+base[i]
        ans %= mod
print(ans)
0