結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー 👑 cologne
提出日時 2026-10-06 13:47:15
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 258 ms / 2,000 ms
+ 167µs
コード長 1,584 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 258 ms
コンパイル使用メモリ 82,336 KB
実行使用メモリ 201,084 KB
最終ジャッジ日時 2026-10-06 13:47:39
合計ジャッジ時間 17,739 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

from typing import List, Tuple

int1 = lambda x: int(x) - 1
input = lambda: sys.stdin.readline().rstrip('\n')
ii = lambda: int(input())
vi = lambda: list(map(int, input().split()))
vi1 = lambda: list(map(int1, input().split()))


def dbg(*args, **kwargs):
    print(*(repr(arg) for arg in args), *(f'{k}: {repr(v)}' for k, v in kwargs.items()),
          sep='; ', file=sys.stderr, flush=True)


def main():
    q = ii()
    stk = []
    arr = []
    for _ in range(q):
        s = input()
        if s == '2':
            rm = arr.pop()
            if stk and stk[-1] is None:
                stk.pop()
            elif rm == '(':
                stk.pop()
            elif rm == '|':
                stk.pop()
                stk.append('(')
            elif rm == ')':
                stk.append('|')

        else:
            c = s[-1]
            arr.append(c)
            if stk and stk[-1] is None:
                stk.append(None)
            elif c == '(':
                stk.append('(')
            elif c == '|':
                if stk and stk[-1] == '(':
                    stk.pop()
                    stk.append('|')
                else:
                    stk.append(None)
            elif c == ')':
                if stk and stk[-1] == '|':
                    stk.pop()
                else:
                    stk.append(None)
        print('No' if stk else 'Yes')


def _start():
    if (ret := main()) is not None:
        print(*ret) if isinstance(ret, List) or isinstance(ret, Tuple) else print(ret)


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