結果

問題 No.592 括弧の対応 (2)
ユーザー 👑 yumechiyumechi
提出日時 2017-11-24 23:56:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 146 ms / 5,000 ms
コード長 494 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 102,128 KB
最終ジャッジ日時 2023-08-18 05:33:27
合計ジャッジ時間 2,032 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,360 KB
testcase_01 AC 146 ms
98,708 KB
testcase_02 AC 144 ms
102,128 KB
testcase_03 AC 130 ms
97,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = input()
leftcounter = rightcounter = 0
llist, rlist, tlist = [], [], []
for i in range(N):
    if S[i] == "(":
        leftcounter += 1
        llist.append(i + 1)
    if S[i] == ")":
        rightcounter += 1
        rlist.append(i + 1)
        if leftcounter >= rightcounter:
            l = llist.pop()
            r = rlist.pop()
            tlist.append([l, r])

ans = [0]*N
for e in tlist:
    ans[e[0]-1] = str(e[1])
    ans[e[1]-1] = str(e[0])
print("\n".join(ans))
0