結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー カプモカ
提出日時 2026-04-18 01:21:58
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 1,307 ms / 2,000 ms
コード長 990 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 488 ms
コンパイル使用メモリ 20,824 KB
実行使用メモリ 75,488 KB
最終ジャッジ日時 2026-04-18 01:22:36
合計ジャッジ時間 32,773 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

readline = sys.stdin.readline
#input_data = sys.stdin.read().split('\n')
#print(input_data)
Q = readline().split()#int(input_data[0])
#print(Q)

st = [''] * 800005
history_sz = [0] * 800005
history_char = [''] * 800005
history_idx = [0] * 800005
sz = 0
L = 0
out = []
#idx = 1

for q in range(int(Q[0])):
    q_type = readline().split()#input_data[idx].split()
    if q_type[0] == "1":
        L += 1
        history_idx[L] = sz
        history_char[L] = st[sz]
        st[sz] = q_type[1]

        sz += 1
        if sz >= 3 and st[sz-3] == '(' and st[sz-2] == '|' and st[sz-1] == ')':
            sz -= 3
        history_sz[L] = sz

        if sz == 0:
            out.append("Yes")
        else:
            out.append("No")

    else:
        st[history_idx[L]] = history_char[L]
        L -= 1
        sz = history_sz[L]

        if sz == 0:
            out.append("Yes")
        else:
            out.append("No")
    
    #idx += 1

sys.stdout.write('\n'.join(out) + '\n')
0