結果
| 問題 | No.592 括弧の対応 (2) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-02-07 20:58:42 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 4,632 ms / 5,000 ms |
| コード長 | 773 bytes |
| 記録 | |
| コンパイル時間 | 92 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 23,564 KB |
| 最終ジャッジ日時 | 2024-09-18 22:32:38 |
| 合計ジャッジ時間 | 10,431 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 |
ソースコード
import array
def main():
N = int(input())
S = input()
D = []
d = 1
for s in S:
if s == "(":
D.append(d)
d += 1
else:
d -= 1
D.append(d)
idx_stack = array.array("q", [])
depth_stack = array.array("q", [-1])
correspond = array.array("q", [-1] * N)
for idx, depth in enumerate(D):
idx_stack.append(idx)
depth_stack.append(depth)
if depth_stack[-1] == depth_stack[-2]:
start = idx_stack[-2]
end = idx_stack[-1]
correspond[start] = end
correspond[end] = start
idx_stack = idx_stack[:-2]
depth_stack = depth_stack[:-2]
for c in correspond:
print(c+1)
main()