結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-17 23:02:29 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
AC
|
| 実行時間 | 408 ms / 2,000 ms |
| コード長 | 1,377 bytes |
| 記録 | |
| コンパイル時間 | 446 ms |
| コンパイル使用メモリ | 20,828 KB |
| 実行使用メモリ | 144,420 KB |
| 最終ジャッジ日時 | 2026-04-17 23:02:48 |
| 合計ジャッジ時間 | 14,564 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
import sys
def solve():
input_data = sys.stdin.read().splitlines()
if not input_data:
return
Q = int(input_data[0])
parent = [0] * (Q + 1)
char_at = [""] * (Q + 1)
depth = [0] * (Q + 1)
s_stack_tops = [0]
node_count = 0
results = []
for i in range(1, Q + 1):
line = input_data[i]
if line[0] == '1':
c = line[2]
prev_top = s_stack_tops[-1]
new_top = prev_top
matched = False
if c == ')' and depth[prev_top] >= 2:
mid = prev_top
top = parent[mid]
if char_at[mid] == '|' and char_at[top] == '(':
new_top = parent[top]
matched = True
if not matched:
node_count += 1
char_at[node_count] = c
parent[node_count] = prev_top
depth[node_count] = depth[prev_top] + 1
new_top = node_count
s_stack_tops.append(new_top)
else:
if len(s_stack_tops) > 1:
s_stack_tops.pop()
if s_stack_tops[-1] == 0:
results.append("Yes")
else:
results.append("No")
sys.stdout.write("\n".join(results) + "\n")
if __name__ == "__main__":
solve()