結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー arahi10
提出日時 2026-09-30 16:25:36
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,120 ms / 2,000 ms
+ 390µs
コード長 1,193 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 75 ms
コンパイル使用メモリ 81,008 KB
実行使用メモリ 199,016 KB
最終ジャッジ日時 2026-09-30 16:26:20
合計ジャッジ時間 40,885 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def check(s):
    stack = []
    for letter in s:
        if letter in "(|":
            stack.append(letter)
        else:
            if len(stack) >= 2 and stack[-2] == "(" and stack[-1] == "|":
                stack.pop()
                stack.pop()
            else:
                return False
    return not stack


def do_one_step(stack: list, letter: str):
    if letter in "(|":
        stack.append(letter)
        return "pop", False
    if len(stack) >= 2 and stack[-2] == "(" and stack[-1] == "|":
        stack.pop()
        stack.pop()
        return "push", not stack
    else:
        stack.append(")")
        return "pop", False


def do_reverse_operation(stack: list, ope):
    if ope == "pop":
        stack.pop()
    else:
        stack.append("(")
        stack.append("|")


def solve():
    stack = []
    history = [(None, True)]
    for _ in range(int(input())):
        query = input().split()
        if len(query) == 1:
            ope, _ = history.pop()
            do_reverse_operation(stack, ope)
        else:
            history.append(do_one_step(stack, query[1]))
        print("Yes" if history[-1][1] else "No")


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