結果

問題 No.1646 Avoid Palindrome
ユーザー rin204rin204
提出日時 2022-04-15 16:49:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,038 ms / 3,000 ms
コード長 1,198 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 79,488 KB
最終ジャッジ日時 2024-06-07 01:23:43
合計ジャッジ時間 23,856 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
59,136 KB
testcase_01 AC 51 ms
60,928 KB
testcase_02 AC 50 ms
60,416 KB
testcase_03 AC 53 ms
61,440 KB
testcase_04 AC 1,026 ms
78,720 KB
testcase_05 AC 1,022 ms
78,720 KB
testcase_06 AC 547 ms
78,848 KB
testcase_07 AC 1,038 ms
78,976 KB
testcase_08 AC 566 ms
78,976 KB
testcase_09 AC 842 ms
79,104 KB
testcase_10 AC 727 ms
78,976 KB
testcase_11 AC 716 ms
78,976 KB
testcase_12 AC 869 ms
79,104 KB
testcase_13 AC 1,036 ms
78,976 KB
testcase_14 AC 564 ms
79,104 KB
testcase_15 AC 589 ms
79,104 KB
testcase_16 AC 584 ms
79,104 KB
testcase_17 AC 587 ms
79,232 KB
testcase_18 AC 566 ms
79,488 KB
testcase_19 AC 573 ms
78,976 KB
testcase_20 AC 585 ms
78,848 KB
testcase_21 AC 599 ms
78,976 KB
testcase_22 AC 571 ms
79,232 KB
testcase_23 AC 584 ms
78,848 KB
testcase_24 AC 609 ms
79,232 KB
testcase_25 AC 609 ms
79,104 KB
testcase_26 AC 604 ms
78,976 KB
testcase_27 AC 614 ms
78,976 KB
testcase_28 AC 599 ms
79,104 KB
testcase_29 AC 600 ms
79,104 KB
testcase_30 AC 603 ms
79,104 KB
testcase_31 AC 609 ms
79,360 KB
testcase_32 AC 658 ms
79,104 KB
testcase_33 AC 595 ms
79,232 KB
testcase_34 AC 889 ms
78,720 KB
testcase_35 AC 41 ms
52,096 KB
testcase_36 AC 41 ms
51,968 KB
testcase_37 AC 43 ms
52,096 KB
testcase_38 AC 42 ms
51,712 KB
testcase_39 AC 41 ms
52,224 KB
testcase_40 AC 42 ms
51,712 KB
testcase_41 AC 42 ms
52,352 KB
testcase_42 AC 43 ms
51,968 KB
testcase_43 AC 607 ms
79,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

def f(S):
    if S == "?":
        return -1
    else:
        return ord(S) - 97

n = int(input())
S = input()

if n == 1:
    if S == "?":
        print(26)
    else:
        print(1)
    exit()

S = list(map(f, S))
dp = [0] * (26 * 26)

if S[0] == -1:
    l1 = list(range(26))
else:
    l1 = [S[0]]

if S[1] == -1:
    l2 = list(range(26))
else:
    l2 = [S[1]]

for i in l1:
    for j in l2:
        if i != j:
            dp[i * 26 + j] = 1

for s in S[2:]:
    ndp = [0] * (26 * 26)
    cum = [0] * 26
    for i in range(26):
        for j in range(26):
            cum[j] += dp[26 * i + j]
    if s != -1:
        for i in range(26):
            for j in range(26):
                if i == j:
                    continue
                if s != -1:
                    if s != i and s != j:
                        ndp[26 * j + s] += dp[26 * i + j]
                        ndp[26 * j + s] %= MOD
    else:
        for j in range(26):
            for k in range(26):
                if j != k:
                    ndp[26 * j + k] += cum[j] - dp[26 * k + j]
                    ndp[26 * j + k] %= MOD
                

                    

    dp = ndp

print(sum(dp) % MOD)
0