結果

問題 No.592 括弧の対応 (2)
ユーザー TsubasaTsubasa
提出日時 2018-02-07 20:43:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 705 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 11,920 KB
実行使用メモリ 26,540 KB
最終ジャッジ日時 2023-10-19 01:49:37
合計ジャッジ時間 6,868 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,136 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0