結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー arahi10
提出日時 2026-09-30 16:23:31
言語 Python3
(3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
TLE  
実行時間 -
コード長 1,193 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 58 ms
コンパイル使用メモリ 15,360 KB
実行使用メモリ 34,152 KB
最終ジャッジ日時 2026-09-30 16:24:53
合計ジャッジ時間 81,158 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other TLE * 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