結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー Nattt
提出日時 2026-04-17 22:27:51
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 940 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 687 ms
コンパイル使用メモリ 20,700 KB
実行使用メモリ 75,820 KB
最終ジャッジ日時 2026-04-17 22:28:07
合計ジャッジ時間 13,873 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

def solve():
    input_data = sys.stdin.read().split()
    if not input_data:
        return
        
    Q = int(input_data[0])
    
    st = [''] * (Q + 5)
    hist_len = [0] * (Q + 5)
    
    top = 0
    s_len = 0
    
    idx = 1
    out = []
    
    for _ in range(Q):
        t = input_data[idx]
        if t == '1':
            c = input_data[idx+1]
            idx += 2
            
            st[top] = c
            top += 1
            
            if top >= 3 and st[top-3] == '(' and st[top-2] == '|' and st[top-1] == ')':
                top -= 3
                
            s_len += 1
            hist_len[s_len] = top
            
        else:
            idx += 1
            s_len -= 1
            top = hist_len[s_len]
            
        if top == 0:
            out.append("Yes")
        else:
            out.append("No")
            
    print('\n'.join(out))

if __name__ == '__main__':
    solve()
0