結果

問題 No.22 括弧の対応
ユーザー wesoweeenwesoweeen
提出日時 2021-09-17 00:09:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 417 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 10,992 KB
実行使用メモリ 8,888 KB
最終ジャッジ日時 2023-09-12 04:16:15
合計ジャッジ時間 1,628 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,816 KB
testcase_01 AC 17 ms
7,948 KB
testcase_02 AC 16 ms
7,792 KB
testcase_03 AC 19 ms
8,888 KB
testcase_04 AC 17 ms
8,416 KB
testcase_05 AC 17 ms
8,360 KB
testcase_06 AC 16 ms
8,528 KB
testcase_07 AC 17 ms
8,652 KB
testcase_08 AC 16 ms
8,360 KB
testcase_09 AC 17 ms
8,268 KB
testcase_10 AC 18 ms
8,488 KB
testcase_11 AC 17 ms
8,296 KB
testcase_12 AC 18 ms
8,516 KB
testcase_13 AC 18 ms
8,616 KB
testcase_14 AC 15 ms
7,824 KB
testcase_15 AC 20 ms
8,616 KB
testcase_16 AC 17 ms
8,528 KB
testcase_17 AC 16 ms
7,820 KB
testcase_18 AC 15 ms
7,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N, K = map(int, (input().split()))
    S = input()
    tmp = []
    stack = []
    for i, s in enumerate(S, 1):
        if s == '(':
            tmp.append(i)
        elif s == ')':
            p = tmp.pop(-1)
            stack.append((p, i))
    for j in stack:
        if j[0] == K:
            print(j[1])
        elif j[1] == K:
            print(j[0])
    

if __name__ == '__main__':
    main()
0