結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー zer0-star
提出日時 2026-04-17 21:52:45
言語 Python3
(3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
TLE  
実行時間 -
コード長 981 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 57 ms
コンパイル使用メモリ 15,360 KB
実行使用メモリ 67,584 KB
最終ジャッジ日時 2026-09-07 23:37:25
合計ジャッジ時間 79,391 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other TLE * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

Q = int(input())

stack = [(0, 0)]

for _ in range(Q):
    text = input()
    if text[0] == "2":
        stack.pop()
    else:
        c = text[-1]
        s, v = stack[-1]
        ns = -1
        nv = -1
        if s == -1:
            pass
        elif s == 0:
            if c == "(":
                ns = 1
                nv = 1
        elif s == 1 or s == 3:
            if c == "|":
                ns = 2
                nv = v
            elif c == "(" and s == 1:
                ns = 1
                nv = v * 2
        elif s == 2 or s == 4:
            if c == ")":
                nv = v // 2
                if nv == 0:
                    ns = 99999
                elif v % 2 == 0:
                    ns = 3
                else:
                    ns = 4
            elif c == "(" and s == 2:
                ns = 1
                nv = v * 2 + 1
        stack.append((ns, nv))

    if stack[-1][0] == 99999:
        print("Yes")
    else:
        print("No")
0