結果

問題 No.1646 Avoid Palindrome
ユーザー 👑 H20H20
提出日時 2021-08-14 02:04:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 823 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 82,596 KB
実行使用メモリ 444,264 KB
最終ジャッジ日時 2024-04-14 23:41:23
合計ジャッジ時間 55,291 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
62,204 KB
testcase_01 AC 44 ms
61,816 KB
testcase_02 AC 44 ms
60,832 KB
testcase_03 WA -
testcase_04 AC 1,568 ms
423,004 KB
testcase_05 AC 1,428 ms
423,088 KB
testcase_06 AC 1,607 ms
411,052 KB
testcase_07 WA -
testcase_08 AC 1,555 ms
426,456 KB
testcase_09 WA -
testcase_10 AC 1,531 ms
417,660 KB
testcase_11 AC 1,496 ms
407,932 KB
testcase_12 WA -
testcase_13 AC 1,434 ms
426,580 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1,780 ms
430,216 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 1,486 ms
443,832 KB
testcase_30 AC 1,474 ms
444,116 KB
testcase_31 AC 1,565 ms
444,264 KB
testcase_32 AC 1,521 ms
443,788 KB
testcase_33 AC 1,489 ms
444,112 KB
testcase_34 WA -
testcase_35 AC 38 ms
54,128 KB
testcase_36 AC 38 ms
53,436 KB
testcase_37 WA -
testcase_38 AC 39 ms
53,080 KB
testcase_39 AC 42 ms
60,304 KB
testcase_40 AC 44 ms
61,132 KB
testcase_41 AC 44 ms
60,868 KB
testcase_42 AC 43 ms
60,268 KB
testcase_43 AC 1,499 ms
443,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = input()
mod = 998244353
DP = [[[0] * 26 for _ in range(26)] for _ in range(N+1)]
DP[0][0][0]=1
for n in range(N):
    if S[n]=='?':
        TEMP = [0]*26
        for i in range(26):
            for j in range(26):
                TEMP[j]+=DP[n][j][i]
        for j in range(26):
            for k in range(26):
                if j!=k:
                    DP[n+1][k][j]=(TEMP[j]-DP[n][j][k])%mod
                if j==0 and k==0 and n==0:
                    DP[1][0][0]=1

    else:
        k = ord(S[n])-97
        for i in range(26):
            for j in range(26):
                if (i!=k or n<=1) and (j!=k or n==0):
                    DP[n+1][k][j]=(DP[n+1][k][j]+DP[n][j][i])%mod                    
ans = 0
for i in range(26):
    for j in range(26):
        ans += DP[N][i][j]
print(ans%mod)
0