結果

問題 No.1677 mæx
ユーザー rlangevinrlangevin
提出日時 2023-02-06 23:47:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 354 ms / 2,000 ms
コード長 1,495 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 87,260 KB
実行使用メモリ 93,124 KB
最終ジャッジ日時 2023-09-18 09:18:53
合計ジャッジ時間 7,052 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,424 KB
testcase_01 AC 72 ms
71,308 KB
testcase_02 AC 73 ms
71,460 KB
testcase_03 AC 72 ms
71,636 KB
testcase_04 AC 354 ms
93,124 KB
testcase_05 AC 335 ms
92,956 KB
testcase_06 AC 346 ms
92,020 KB
testcase_07 AC 334 ms
92,432 KB
testcase_08 AC 333 ms
91,204 KB
testcase_09 AC 325 ms
91,400 KB
testcase_10 AC 334 ms
92,612 KB
testcase_11 AC 310 ms
91,580 KB
testcase_12 AC 310 ms
90,508 KB
testcase_13 AC 319 ms
91,368 KB
testcase_14 AC 154 ms
89,948 KB
testcase_15 AC 151 ms
89,788 KB
testcase_16 AC 157 ms
89,420 KB
testcase_17 AC 165 ms
89,524 KB
testcase_18 AC 152 ms
89,808 KB
testcase_19 AC 72 ms
71,424 KB
testcase_20 AC 76 ms
71,604 KB
testcase_21 AC 125 ms
91,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353

def lst(n):
    if n == "0":
        return [1, 0, 0]
    elif n == "1":
        return [0, 1, 0]
    elif n == "2":
        return [0, 0, 1]
    elif n == "?":
        return [1, 1, 1]
    else:
        return n
        
def calc(X, Y, ae):
    temp = [0, 0, 0]
    if ae == "a":
        temp[2] = sum(X) * Y[2] + sum(Y) * X[2] - X[2] * Y[2]
        temp[1] = (X[1] + X[0]) * (Y[1] + Y[0]) - Y[0] * X[0]
        temp[0] = X[0] * Y[0]
    elif ae == "e":
        temp[0] = (X[1] + X[2]) * (Y[1] + Y[2])
        temp[1] = (X[0] + X[2]) * (Y[0] + Y[2]) - X[2] * Y[2]
        temp[2] = X[0] * Y[1] + X[1] * Y[0]
    else:
        temp[0] = (X[1] + X[2]) * (Y[1] + Y[2]) + X[0] * Y[0]
        temp[1] = (X[0] + X[2]) * (Y[0] + Y[2]) - X[2] * Y[2] + (X[1] + X[0]) * (Y[1] + Y[0]) - Y[0] * X[0]
        temp[2] = X[0] * Y[1] + X[1] * Y[0] + sum(X) * Y[2] + sum(Y) * X[2] - X[2] * Y[2]
    temp[0] %= mod
    temp[1] %= mod
    temp[2] %= mod
    # print("calc_test", X, Y, temp, ae)
    return temp

S = list(input())
K = int(input())
stack = []
for s in S:
    if s == "m" or s == "x":
        continue
    elif s != ")":
        stack.append(s)
    else:
        A = lst(stack.pop())
        stack.pop()
        B = lst(stack.pop())
        stack.pop()
        ae = stack.pop()
        stack.append(calc(A, B, ae))
    # print("test", s, stack)     

if stack[0] in ["0", "1", "2"]:
    if K == int(stack[0]):
        print(1)
    else:
        print(0)
else:
    print(stack[0][K])
0