結果

問題 No.592 括弧の対応 (2)
ユーザー kichirb3kichirb3
提出日時 2018-03-14 07:15:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 124 ms / 5,000 ms
コード長 644 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 10,824 KB
実行使用メモリ 21,108 KB
最終ジャッジ日時 2023-08-16 16:54:06
合計ジャッジ時間 1,197 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,948 KB
testcase_01 AC 124 ms
21,108 KB
testcase_02 AC 117 ms
21,108 KB
testcase_03 AC 122 ms
20,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.592 括弧の対応 (2)
https://yukicoder.me/problems/no/592

"""
import sys
from sys import stdin
input = stdin.readline


def solve(S):
    res = [0] * (len(S)+1)
    status = []
    for i, s in enumerate(S, start=1):
        if s == '(':
            status.append(i)
        elif s == ')':
            try:
                t = status.pop()
            except:
                return 0
            res[i] = t
            res[t] = i
    return res


def main(args):
    N = int(input())
    S = input().strip()
    ans = solve(S)
    print(*ans[1:], sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])
0