結果

問題 No.22 括弧の対応
ユーザー osrgy01osrgy01
提出日時 2021-02-03 10:27:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 458 bytes
コンパイル時間 703 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 9,236 KB
最終ジャッジ日時 2023-09-12 11:46:36
合計ジャッジ時間 1,535 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,184 KB
testcase_01 AC 16 ms
8,160 KB
testcase_02 AC 15 ms
8,176 KB
testcase_03 AC 19 ms
9,124 KB
testcase_04 AC 17 ms
8,676 KB
testcase_05 AC 18 ms
8,536 KB
testcase_06 AC 18 ms
8,920 KB
testcase_07 AC 18 ms
8,972 KB
testcase_08 AC 17 ms
8,636 KB
testcase_09 AC 18 ms
8,696 KB
testcase_10 AC 17 ms
9,032 KB
testcase_11 AC 16 ms
8,580 KB
testcase_12 AC 18 ms
8,676 KB
testcase_13 AC 19 ms
9,060 KB
testcase_14 AC 16 ms
8,352 KB
testcase_15 AC 19 ms
9,236 KB
testcase_16 AC 18 ms
9,020 KB
testcase_17 AC 16 ms
8,064 KB
testcase_18 AC 15 ms
8,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k=map(int,input().split())
s=[(i+1,j) for i,j in enumerate(input())]
stack=[]
if s[k-1][1]=='(':
    for i,j in s:
        if j=='(':
            stack.append(i)
        else:
            n=stack.pop()
            if n==k:
                print(i)
                exit()
else:
    for i,j in s:
        if j=='(':
            stack.append(i)
        else:
            if i==k:
                print(stack[-1])
                exit()
            stack.pop()
0