結果

問題 No.592 括弧の対応 (2)
ユーザー GrayCoderGrayCoder
提出日時 2017-11-11 17:44:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 248 ms / 5,000 ms
コード長 510 bytes
コンパイル時間 834 ms
コンパイル使用メモリ 10,936 KB
実行使用メモリ 33,140 KB
最終ジャッジ日時 2023-08-16 07:42:47
合計ジャッジ時間 2,466 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,944 KB
testcase_01 AC 248 ms
32,764 KB
testcase_02 AC 242 ms
33,140 KB
testcase_03 AC 241 ms
32,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N = int(input())
    S = input()

    lst = [0] * N
    dic = dict()
    stack = []
    apnd = stack.append
    pop_ = stack.pop
    i = 1
    for j, s in enumerate(S):
        if s == '(':
            apnd(i)
            lst[j] = i
            dic[i] = dic.get(i, []) + [j]
            i += 1
        else:
            x = pop_()
            lst[j] = x
            dic[x] = dic[x] + [j]

    for i, j in enumerate(lst):
        a, b = dic[j]
        x = a ^ b ^ i
        print(x + 1)

main()
0