結果

問題 No.1646 Avoid Palindrome
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2021-08-13 23:05:41
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 996 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 649,140 KB
最終ジャッジ日時 2024-04-14 20:09:22
合計ジャッジ時間 89,072 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
65,268 KB
testcase_01 AC 56 ms
67,192 KB
testcase_02 AC 52 ms
64,516 KB
testcase_03 AC 59 ms
68,372 KB
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 MLE -
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 MLE -
testcase_29 MLE -
testcase_30 MLE -
testcase_31 MLE -
testcase_32 MLE -
testcase_33 MLE -
testcase_34 MLE -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 49 ms
64,180 KB
testcase_38 AC 47 ms
62,300 KB
testcase_39 AC 45 ms
60,984 KB
testcase_40 AC 45 ms
61,816 KB
testcase_41 AC 53 ms
64,896 KB
testcase_42 AC 52 ms
64,548 KB
testcase_43 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from _collections import defaultdict
n=int(input())
s=["#"]+list(input())
dic={}
dic["#"]=-1
dic["."]=-2
dic["?"]=-34
al=list(".#abcdefghijklmnopqrstuvwxyz")

for x in al:dic[x]=ord(x)-97
for i in range(n+1):
    s[i]=dic[s[i]]


dp=[[[0]*33 for _ in range(33)] for i in range(n+2)]
sumdp=[[0]*(33) for i in range(n+1)]

mod=998244353
dp[0][-2][-1]=1

for i in range(n+1):
    for x in range(-2,26):
      for y in range(-2,26):
        if i>=2 and ( x<0 or y<0):continue
        if x==y:continue
        if s[i]==-34:
            dp[i][x][y]+=sumdp[i-1][x]
            dp[i][x][y]-=dp[i-1][y][x]
            dp[i][x][y]%=mod


        if i==n:continue
        if s[i+1]!=-34:
            if s[i+1]==y or s[i+1]==x:continue
            dp[i+1][y][s[i+1]]+=dp[i][x][y]
            dp[i + 1][y][ s[i + 1]]%=mod
        else:
            sumdp[i][y]+=dp[i][x][y]
            sumdp[i][y]%=mod

ans=0

for x in range(26):
    for y in range(26):
        ans+=dp[n][x][y]
        ans%=mod

print(ans)

0