結果

問題 No.1677 mæx
ユーザー 👑 KazunKazun
提出日時 2021-09-10 22:55:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 1,246 bytes
コンパイル時間 1,646 ms
コンパイル使用メモリ 86,724 KB
実行使用メモリ 81,160 KB
最終ジャッジ日時 2023-09-02 20:23:23
合計ジャッジ時間 5,582 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,608 KB
testcase_01 AC 93 ms
71,692 KB
testcase_02 AC 93 ms
71,688 KB
testcase_03 AC 71 ms
71,440 KB
testcase_04 AC 178 ms
80,552 KB
testcase_05 AC 181 ms
81,160 KB
testcase_06 AC 173 ms
80,512 KB
testcase_07 AC 182 ms
80,344 KB
testcase_08 AC 181 ms
80,800 KB
testcase_09 AC 178 ms
80,540 KB
testcase_10 AC 187 ms
80,404 KB
testcase_11 AC 183 ms
81,076 KB
testcase_12 AC 179 ms
80,436 KB
testcase_13 AC 182 ms
80,200 KB
testcase_14 AC 179 ms
80,232 KB
testcase_15 AC 175 ms
80,104 KB
testcase_16 AC 176 ms
80,528 KB
testcase_17 AC 178 ms
80,340 KB
testcase_18 AC 176 ms
80,116 KB
testcase_19 AC 70 ms
71,284 KB
testcase_20 AC 70 ms
71,528 KB
testcase_21 AC 175 ms
80,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def convolute(a,b,op):
    c=[0,0,0]

    for i in range(3):
        for j in range(3):
            c[op[i][j]]+=a[i]*b[j]

    for i in range(3):
        c[i]%=Mod
    return c

S=input()
K=int(input())

MAX=[[max(x,y) for x in [0,1,2]] for y in [0,1,2]]
MEX=[[1,2,1],[2,0,0],[1,0,0]]

if len(S)==1:
    if S=="?":
        print(1)
    else:
        if int(S)==K:
            print(1)
        else:
            print(0)
    exit()

def three_pop():
    T=[]
    for _ in range(3):
        T.append(X.pop())
    return T[::-1]

from collections import deque
Mod=998244353
i=0
X=deque([])
while i<len(S):
    if S[i]=="m":
        X.append(S[i:i+3])
        i+=3
    elif S[i]=="(":
        i+=1
    elif S[i]==",":
        i+=1
    elif S[i]==")":
        op,a,b=three_pop()
        if op[1]=="a":
            X.append(convolute(a,b,MAX))
        elif op[1]=="e":
            X.append(convolute(a,b,MEX))
        else:
            c=convolute(a,b,MAX)
            d=convolute(a,b,MEX)
            e=[(x+y)%Mod for x,y in zip(c,d)]
            X.append(e)
        i+=1
    else:
        if S[i]=="?":
            X.append([1,1,1])
        else:
            T=[0,0,0]
            T[int(S[i])]=1
            X.append(T)
        i+=1

print(X[0][K])
0