結果
| 問題 |
No.592 括弧の対応 (2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-02-07 20:43:06 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 705 bytes |
| コンパイル時間 | 89 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 28,164 KB |
| 最終ジャッジ日時 | 2024-09-18 21:47:10 |
| 合計ジャッジ時間 | 6,956 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | TLE * 1 -- * 2 |
ソースコード
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 = []
depth_stack = [-1]
correspond = [-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()