結果

問題 No.22 括弧の対応
ユーザー first_vilfirst_vil
提出日時 2021-11-11 22:46:35
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 226 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 10,688 KB
実行使用メモリ 8,928 KB
最終ジャッジ日時 2023-08-15 13:38:17
合計ジャッジ時間 1,733 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,540 KB
testcase_01 AC 17 ms
8,604 KB
testcase_02 AC 17 ms
8,588 KB
testcase_03 AC 20 ms
8,928 KB
testcase_04 AC 18 ms
8,708 KB
testcase_05 AC 18 ms
8,744 KB
testcase_06 AC 19 ms
8,736 KB
testcase_07 AC 19 ms
8,720 KB
testcase_08 AC 18 ms
8,756 KB
testcase_09 AC 18 ms
8,808 KB
testcase_10 AC 20 ms
8,784 KB
testcase_11 AC 19 ms
8,748 KB
testcase_12 AC 20 ms
8,848 KB
testcase_13 AC 19 ms
8,920 KB
testcase_14 AC 17 ms
8,568 KB
testcase_15 AC 20 ms
8,756 KB
testcase_16 AC 21 ms
8,836 KB
testcase_17 AC 18 ms
8,520 KB
testcase_18 AC 17 ms
8,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n,k = map(int,input().split())
s = input()
p = [-1] * n
st = deque([])
for i in range(n):
  if s[i] == '(':
    st.append(i)
  else:
    j = st.pop()
    p[i] = j
    p[j] = i
print(p[k - 1] + 1)
0