結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー a
提出日時 2026-04-19 16:50:28
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 1,216 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 330 ms
コンパイル使用メモリ 85,376 KB
実行使用メモリ 112,364 KB
最終ジャッジ日時 2026-04-19 16:51:22
合計ジャッジ時間 39,606 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import deque
q=int(input())
score=deque()
min_score=deque()
ok=deque()
for i in range(q):
  query=input().split()
  if query[0]=='1':
    c=query[1]
    if c=='(':
      if len(ok)>0 and ok[-1]==0:
      	ok.append(0)
      else:
      	ok.append(0)
      if len(score)>0:
        score.append(score[-1]+1)
        min_score.append(min_score[-1])
      else:
        score.append(1)
        min_score.append(1)
    elif c==')':
    	if len(ok)>0 and ok[-1]==0:
    		ok.append(False)
    	else:
    		ok.append(True)
    	if len(score)>0:
    		score.append(score[-1]-1)
    		min_score.append(min(score[-1],min_score[-1]))
    	else:
    		score.append(-1)
    		min_score.append(-1)
    else:
      if score and score[-1]==0:
        ok.append(0)
      else:
      	if len(ok)>0 and ok[-1]==1:
      		ok.append(False)
      	else:
      		ok.append(True)
      if len(score)>0:
        score.append(score[-1])
        min_score.append(min(score[-1],min_score[-1]))
      else:
        score.append(0)
        min_score.append(0)
  else:
    score.pop()
    min_score.pop()
    ok.pop()
  if len(score)==0 or (score[-1]==0 and min_score[-1]==0 and ok[-1]):
    print("Yes")
  else:
    print("No")
0