結果

問題 No.592 括弧の対応 (2)
ユーザー GrayCoderGrayCoder
提出日時 2017-11-11 17:52:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 330 ms / 5,000 ms
コード長 481 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 32,608 KB
最終ジャッジ日時 2024-05-03 16:41:48
合計ジャッジ時間 1,709 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,624 KB
testcase_01 AC 330 ms
32,128 KB
testcase_02 AC 314 ms
32,392 KB
testcase_03 AC 320 ms
32,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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

main()
0