結果

問題 No.22 括弧の対応
ユーザー 👑 rin204rin204
提出日時 2020-08-20 11:40:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 267 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,584 KB
実行使用メモリ 8,584 KB
最終ジャッジ日時 2023-09-27 13:49:31
合計ジャッジ時間 1,165 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,768 KB
testcase_01 AC 14 ms
7,764 KB
testcase_02 AC 15 ms
7,720 KB
testcase_03 AC 19 ms
8,420 KB
testcase_04 AC 16 ms
8,196 KB
testcase_05 AC 16 ms
7,808 KB
testcase_06 AC 15 ms
8,312 KB
testcase_07 AC 17 ms
8,440 KB
testcase_08 AC 15 ms
8,220 KB
testcase_09 AC 15 ms
8,276 KB
testcase_10 AC 16 ms
8,356 KB
testcase_11 AC 15 ms
8,348 KB
testcase_12 AC 16 ms
8,276 KB
testcase_13 AC 17 ms
8,500 KB
testcase_14 AC 15 ms
7,764 KB
testcase_15 AC 17 ms
8,556 KB
testcase_16 AC 17 ms
8,584 KB
testcase_17 AC 14 ms
7,836 KB
testcase_18 AC 16 ms
7,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
ans = [-1 for _ in range(n)]
lst = []
ss = input().rstrip()
for i, s in enumerate(ss, start = 1):
    if s == "(":
        lst.append(i)
    else:
        n = lst.pop(-1)
        ans[n - 1] = i
        ans[i - 1] = n
print(ans[k - 1])
0