結果

問題 No.1646 Avoid Palindrome
ユーザー 👑 rin204rin204
提出日時 2022-04-15 16:49:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,055 ms / 3,000 ms
コード長 1,198 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 80,556 KB
最終ジャッジ日時 2023-08-26 06:07:50
合計ジャッジ時間 25,315 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
75,872 KB
testcase_01 AC 83 ms
76,468 KB
testcase_02 AC 83 ms
76,464 KB
testcase_03 AC 90 ms
76,468 KB
testcase_04 AC 1,048 ms
80,104 KB
testcase_05 AC 1,051 ms
80,284 KB
testcase_06 AC 565 ms
80,348 KB
testcase_07 AC 1,043 ms
80,416 KB
testcase_08 AC 584 ms
80,440 KB
testcase_09 AC 862 ms
80,128 KB
testcase_10 AC 748 ms
80,252 KB
testcase_11 AC 727 ms
80,356 KB
testcase_12 AC 882 ms
80,192 KB
testcase_13 AC 1,055 ms
80,056 KB
testcase_14 AC 583 ms
80,280 KB
testcase_15 AC 614 ms
80,184 KB
testcase_16 AC 603 ms
80,424 KB
testcase_17 AC 605 ms
80,180 KB
testcase_18 AC 581 ms
80,120 KB
testcase_19 AC 588 ms
80,140 KB
testcase_20 AC 597 ms
80,448 KB
testcase_21 AC 614 ms
80,508 KB
testcase_22 AC 588 ms
80,448 KB
testcase_23 AC 596 ms
80,140 KB
testcase_24 AC 622 ms
80,352 KB
testcase_25 AC 632 ms
80,224 KB
testcase_26 AC 621 ms
80,552 KB
testcase_27 AC 629 ms
80,236 KB
testcase_28 AC 623 ms
80,528 KB
testcase_29 AC 622 ms
80,556 KB
testcase_30 AC 624 ms
80,172 KB
testcase_31 AC 621 ms
80,376 KB
testcase_32 AC 676 ms
80,272 KB
testcase_33 AC 620 ms
80,108 KB
testcase_34 AC 910 ms
80,048 KB
testcase_35 AC 74 ms
71,224 KB
testcase_36 AC 75 ms
71,396 KB
testcase_37 AC 74 ms
71,408 KB
testcase_38 AC 75 ms
71,044 KB
testcase_39 AC 74 ms
71,272 KB
testcase_40 AC 73 ms
71,176 KB
testcase_41 AC 76 ms
71,300 KB
testcase_42 AC 74 ms
71,312 KB
testcase_43 AC 617 ms
80,416 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