結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 01:05:20 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
AC
|
| 実行時間 | 664 ms / 2,000 ms |
| コード長 | 779 bytes |
| 記録 | |
| コンパイル時間 | 412 ms |
| コンパイル使用メモリ | 20,960 KB |
| 実行使用メモリ | 87,884 KB |
| 最終ジャッジ日時 | 2026-04-18 01:05:49 |
| 合計ジャッジ時間 | 21,826 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
import sys
input = sys.stdin.readline
def solve():
Q = int(input())
stack = []
ops_history = []
out = []
for _ in range(Q):
line = input().split()
if line[0] == '1':
c = line[1]
if c == ')' and len(stack) >= 2 and stack[-1] == '|' and stack[-2] == '(':
ops_history.append(('pop2',))
stack.pop(); stack.pop()
else:
ops_history.append(('push', c))
stack.append(c)
else:
op = ops_history.pop()
if op[0] == 'push':
stack.pop()
else:
stack.append('('); stack.append('|')
out.append('Yes' if not stack else 'No')
sys.stdout.write('\n'.join(out) + '\n')
solve()