結果

問題 No.1677 mæx
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2021-09-11 00:00:08
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,038 bytes
コンパイル時間 515 ms
コンパイル使用メモリ 86,976 KB
実行使用メモリ 94,804 KB
最終ジャッジ日時 2023-09-03 01:28:50
合計ジャッジ時間 5,751 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,224 KB
testcase_01 AC 75 ms
71,204 KB
testcase_02 AC 73 ms
71,192 KB
testcase_03 AC 70 ms
71,132 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 71 ms
71,312 KB
testcase_20 AC 73 ms
71,132 KB
testcase_21 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

s=list(input())
n=len(s)
p=int(input())
stack=[]
ktok={}
mod=998244353
def mex(x,y):
    res=set()
    res.add(x)
    res.add(y)
    for i in range(3):
        if i not in res:return i

for i in range(n):
    if s[i]=="(":stack.append(i)
    if s[i]==")":
        j=stack.pop()
        ktok[j]=i

ktot={}
for i in range(n):
    if s[i]=="(":stack.append(i)
    if s[i]==",":
        j=stack.pop()
        ktot[j]=i

def f(l,r):
    if l==r:
        res=[0,0,0]
        if s[l]=="?":
            res[0]=1
            res[1]=1
            res[2]=1
        else:
            res[int(s[l])]=1
        return res
    dp1=f(l+4,ktot[l+3]-1)
    dp2=f(ktot[l+3]+1,r-1)
    res=[0,0,0]
    for i in range(3):
        for j in range(3):
            if s[l+1]=="a" or s[l+1]=="?":
                res[max(i,j)]+=dp1[i]*dp2[j]%mod
                res[max(i, j)]%=mod
            if s[l + 1] == "e" or s[l + 1] == "?":
                res[mex(i, j)] += dp1[i] * dp2[j] % mod
                res[mex(i, j)] %= mod
    return res

print(f(0,n-1)[p])


0