結果

問題 No.592 括弧の対応 (2)
ユーザー はむ吉🐹はむ吉🐹
提出日時 2017-11-16 14:25:29
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 486 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 10,700 KB
実行使用メモリ 28,208 KB
最終ジャッジ日時 2023-08-16 16:51:39
合計ジャッジ時間 1,276 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,348 KB
testcase_01 AC 128 ms
27,732 KB
testcase_02 AC 124 ms
28,208 KB
testcase_03 AC 121 ms
27,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python

import collections


def check_brackets(s):
    n = len(s)
    res = [-1 for _ in range(n)]
    stack = collections.deque()
    for i, c in enumerate(s):
        if c == '(':
            stack.append(i)
        else:
            j = stack.pop()
            res[i] = j
            res[j] = i
    return res


def main():
    _ = input()
    s = input()
    res = check_brackets(s)
    print(*(r + 1 for r in res), sep="\n")


if __name__ == '__main__':
    main()
0