結果

問題 No.592 括弧の対応 (2)
ユーザー GrayCoder
提出日時 2017-11-11 17:44:22
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 312 ms / 5,000 ms
コード長 510 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 35,644 KB
最終ジャッジ日時 2024-11-24 19:17:36
合計ジャッジ時間 2,186 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

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