結果

問題 No.592 括弧の対応 (2)
ユーザー 👑 yumechiyumechi
提出日時 2017-11-24 23:56:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 115 ms / 5,000 ms
コード長 494 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 102,656 KB
最終ジャッジ日時 2024-05-05 11:46:18
合計ジャッジ時間 1,119 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
51,584 KB
testcase_01 AC 115 ms
99,328 KB
testcase_02 AC 108 ms
102,656 KB
testcase_03 AC 104 ms
97,664 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