結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー titia
提出日時 2026-04-21 05:27:04
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 395 ms / 2,000 ms
コード長 675 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 248 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 255,780 KB
最終ジャッジ日時 2026-04-21 05:27:23
合計ジャッジ時間 14,806 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

Q=int(input())

A=[]
X=[]
D=dict()

for tests in range(Q):
    #print(A)
    #print(X)
    L=input().split()

    if L[0]=="1":
        x=L[1]

        A.append(x)
        X.append((x,len(A)-1))

        while len(X)>=3 and X[-1][0]==")" and X[-2][0]=="|" and X[-3][0]=="(":
            a=X.pop()
            b=X.pop()
            c=X.pop()
            D[a[1]]=[b,c]
    else:
        k=A.pop()

        if X and X[-1][0]==k and X[-1][1]==len(A):
            X.pop()
        else:
            X.append(D[len(A)][1])
            X.append(D[len(A)][0])

    if X==[]:
        print("Yes")
    else:
        print("No")

        
        
0