結果

問題 No.592 括弧の対応 (2)
ユーザー maspymaspy
提出日時 2020-01-28 22:58:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 184 ms / 5,000 ms
コード長 423 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 10,592 KB
実行使用メモリ 24,000 KB
最終ジャッジ日時 2023-10-13 20:56:05
合計ジャッジ時間 1,706 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,768 KB
testcase_01 AC 184 ms
21,624 KB
testcase_02 AC 184 ms
24,000 KB
testcase_03 AC 169 ms
20,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = read().rstrip().decode()

stack = [(-1,'$')]
pair = [0] * (N+1)
for i,s in enumerate(S,1):
    if s == ')' and stack[-1][1] == '(':
        j = stack[-1][0]
        pair[i] = j
        pair[j] = i
        stack.pop()
    else:
        stack.append((i,s))

print(*pair[1:], sep='\n')
0