結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー YuukunA
提出日時 2026-04-18 14:06:27
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 497 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 802 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 83,804 KB
最終ジャッジ日時 2026-04-18 14:07:15
合計ジャッジ時間 37,398 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

input = sys.stdin.readline

Q = int(input())
st = [(0, 0, 0, 0)]

for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        a, b, ma, mb = st[-1]
        c = q[1]
        if c == '(':
            a += 1
        elif c == '|':
            a -= 1
            b += 1
        else:
            b -= 1
        st.append((a, b, min(ma, a), min(mb, b)))
    else:
        st.pop()

    a, b, ma, mb = st[-1]
    print("Yes" if a == 0 and b == 0 and ma >= 0 and mb >= 0 else "No")
0