結果

問題 No.1646 Avoid Palindrome
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-08-13 22:26:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 685 ms / 3,000 ms
コード長 1,504 bytes
コンパイル時間 918 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 78,100 KB
最終ジャッジ日時 2023-08-08 09:57:43
合計ジャッジ時間 21,039 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,176 KB
testcase_01 AC 79 ms
76,056 KB
testcase_02 AC 84 ms
75,944 KB
testcase_03 AC 81 ms
76,144 KB
testcase_04 AC 519 ms
77,440 KB
testcase_05 AC 518 ms
77,460 KB
testcase_06 AC 501 ms
77,444 KB
testcase_07 AC 519 ms
77,324 KB
testcase_08 AC 502 ms
77,132 KB
testcase_09 AC 485 ms
77,340 KB
testcase_10 AC 507 ms
77,488 KB
testcase_11 AC 502 ms
77,516 KB
testcase_12 AC 520 ms
77,488 KB
testcase_13 AC 528 ms
77,632 KB
testcase_14 AC 587 ms
77,784 KB
testcase_15 AC 602 ms
77,340 KB
testcase_16 AC 591 ms
77,568 KB
testcase_17 AC 605 ms
77,816 KB
testcase_18 AC 592 ms
77,488 KB
testcase_19 AC 589 ms
77,552 KB
testcase_20 AC 599 ms
77,688 KB
testcase_21 AC 615 ms
77,532 KB
testcase_22 AC 595 ms
77,536 KB
testcase_23 AC 599 ms
77,268 KB
testcase_24 AC 628 ms
77,748 KB
testcase_25 AC 638 ms
78,100 KB
testcase_26 AC 629 ms
77,468 KB
testcase_27 AC 636 ms
77,812 KB
testcase_28 AC 631 ms
77,752 KB
testcase_29 AC 649 ms
77,296 KB
testcase_30 AC 460 ms
77,240 KB
testcase_31 AC 464 ms
77,324 KB
testcase_32 AC 461 ms
77,372 KB
testcase_33 AC 457 ms
77,444 KB
testcase_34 AC 660 ms
77,116 KB
testcase_35 AC 74 ms
71,184 KB
testcase_36 AC 74 ms
71,520 KB
testcase_37 AC 73 ms
71,500 KB
testcase_38 AC 76 ms
71,444 KB
testcase_39 AC 75 ms
71,380 KB
testcase_40 AC 74 ms
71,172 KB
testcase_41 AC 75 ms
71,320 KB
testcase_42 AC 73 ms
71,240 KB
testcase_43 AC 685 ms
77,272 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