結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー ハムたん
提出日時 2026-04-19 15:22:12
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 618 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 283 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 91,544 KB
最終ジャッジ日時 2026-04-19 15:23:30
合計ジャッジ時間 19,069 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 1
other AC * 2 WA * 9 TLE * 1 -- * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

S = ""
c = 0
b = 0
b2 = 0
for i in range(int(input())):
  q = input()
  if q.startswith("1"):
    S += q[2]
    if q[2] == "(":
        c += 1
    elif q[2] == ")":
        c -= 1
        if c < 0:
            b = len(S)
    elif q[2] == "|":
        if c == 0:
            b2 = len(S)
  else:
    if S[-1] == "(":
        c -= 1
    elif S[-1] == ")":
        c += 1
        if len(S)-1 < b:
            b = 0
    elif S[-1] == "|":
        if len(S)-1 < b2:
            b2 = 0
    S = S[:-1]
  print("Yes" if c == 0 and not b and S.count("(") == S.count("|") and "()" not in S and "||" not in S and not b2 else "No")
0