結果

問題 No.1646 Avoid Palindrome
ユーザー ntudantuda
提出日時 2021-08-15 16:23:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,325 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 82,648 KB
実行使用メモリ 444,928 KB
最終ジャッジ日時 2024-04-16 19:03:28
合計ジャッジ時間 59,426 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,376 KB
testcase_01 AC 44 ms
60,544 KB
testcase_02 AC 43 ms
59,904 KB
testcase_03 AC 52 ms
63,616 KB
testcase_04 AC 1,666 ms
423,296 KB
testcase_05 AC 1,605 ms
423,352 KB
testcase_06 AC 1,724 ms
411,648 KB
testcase_07 AC 1,605 ms
423,516 KB
testcase_08 AC 1,665 ms
426,752 KB
testcase_09 AC 1,610 ms
409,468 KB
testcase_10 AC 1,700 ms
417,920 KB
testcase_11 AC 1,582 ms
408,192 KB
testcase_12 AC 1,617 ms
422,784 KB
testcase_13 AC 1,626 ms
426,568 KB
testcase_14 AC 1,788 ms
417,092 KB
testcase_15 AC 1,817 ms
423,936 KB
testcase_16 AC 1,773 ms
415,308 KB
testcase_17 AC 1,846 ms
429,568 KB
testcase_18 AC 1,798 ms
420,700 KB
testcase_19 AC 1,801 ms
419,072 KB
testcase_20 AC 1,819 ms
421,724 KB
testcase_21 AC 1,844 ms
429,056 KB
testcase_22 AC 1,806 ms
417,540 KB
testcase_23 AC 1,847 ms
431,500 KB
testcase_24 AC 2,087 ms
444,928 KB
testcase_25 AC 2,141 ms
444,908 KB
testcase_26 AC 2,085 ms
444,908 KB
testcase_27 AC 2,098 ms
444,788 KB
testcase_28 AC 2,096 ms
444,572 KB
testcase_29 AC 1,572 ms
443,964 KB
testcase_30 AC 1,574 ms
444,560 KB
testcase_31 AC 1,689 ms
444,032 KB
testcase_32 AC 1,611 ms
444,452 KB
testcase_33 AC 1,580 ms
444,416 KB
testcase_34 AC 1,880 ms
444,124 KB
testcase_35 AC 40 ms
52,352 KB
testcase_36 AC 38 ms
52,736 KB
testcase_37 AC 38 ms
52,224 KB
testcase_38 AC 38 ms
52,480 KB
testcase_39 WA -
testcase_40 AC 39 ms
52,480 KB
testcase_41 AC 38 ms
52,736 KB
testcase_42 AC 39 ms
52,352 KB
testcase_43 AC 1,584 ms
444,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
N = int(input())
S = input()
mod = 998244353
dp = [[[0] * 26 for i in range(26)] for j in range(N)]

def code(s):
    return ord(s) - 97

if N == 1:
    if S[0] == "?":
        print(26)
        sys.exit()
    else:
        print(1)
        sys.exit()

if S[0:2] == "??":
    for i in range(26):
        for j in range(26):
            if i != j:
                dp[1][i][j] = 1

elif S[0] == "?":
    j = code(S[1])
    for i in range(26):
        if i != j:
            dp[1][i][j] = 1

elif S[1] == "?":
    j = code(S[0])
    for i in range(26):
        if i != j:
            dp[1][j][i] = 1

else:
    dp[1][code(S[0])][code(S[1])] = 1

for i in range(2,N):
    if S[i] == "?":
        AS = [[0] * 27 for _ in range(26)]
        for k in range(26):
            for j in range(26):
                AS[k][j+1] = AS[k][j] + dp[i-1][j][k]
        for k in range(26):
            for l in range(26):
                if k != l:
                    temp = AS[k][l] + AS[k][-1] - AS[k][l+1]
                    dp[i][k][l] = temp % mod

    else:
        x = code(S[i])
        for j in range(26):
            for k in range(26):
                if j != x and k != x:
                    dp[i][k][x] = (dp[i][k][x] + dp[i-1][j][k]) % mod

ans = 0
for i in range(26):
    ans = (ans + sum(dp[-1][i])) % mod
print(ans)
0