結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー a
提出日時 2026-04-18 00:26:41
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 785 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 309 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 192,144 KB
最終ジャッジ日時 2026-04-18 00:27:22
合計ジャッジ時間 41,233 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

Q=int(input())
from collections import deque
q=deque()
dame=deque()
cur=[0]
for _ in range(Q):
    query=list(input().split())
    if query[0]=='1':
        c=query[1]
        q.append(c)
        if c=='(':
            cur.append(cur[-1]+1)
        elif c=='|':
            cur.append(cur[-1])
            if len(cur)<=2 or cur[-3]==cur[-1]:
                dame.append(len(cur))
        else:
            cur.append(cur[-1]-1)
            if len(cur)<=3 or cur[-3]==cur[-1]:
                dame.append(len(cur))
            elif cur[-1]<0:
                dame.append(len(cur))
    else:
        c=q.pop()
        cur.pop()
        while len(dame)>0 and dame[-1]>=len(cur):
            dame.pop()
    if len(dame)==0 and cur[-1]==0:
        print("Yes")
    else:
        print("No")
0