結果

問題 No.22 括弧の対応
ユーザー soupesuteakasoupesuteaka
提出日時 2016-03-03 21:25:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 383 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 10,488 KB
実行使用メモリ 9,104 KB
最終ジャッジ日時 2023-09-27 13:02:30
合計ジャッジ時間 1,272 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,620 KB
testcase_01 AC 19 ms
8,688 KB
testcase_02 AC 19 ms
8,612 KB
testcase_03 AC 19 ms
9,068 KB
testcase_04 AC 19 ms
8,848 KB
testcase_05 AC 18 ms
8,892 KB
testcase_06 AC 19 ms
8,908 KB
testcase_07 AC 19 ms
9,028 KB
testcase_08 AC 19 ms
8,872 KB
testcase_09 AC 19 ms
8,920 KB
testcase_10 AC 19 ms
8,892 KB
testcase_11 AC 20 ms
8,904 KB
testcase_12 AC 20 ms
8,812 KB
testcase_13 AC 20 ms
8,916 KB
testcase_14 AC 18 ms
8,664 KB
testcase_15 AC 21 ms
9,080 KB
testcase_16 AC 20 ms
9,104 KB
testcase_17 AC 17 ms
8,712 KB
testcase_18 AC 17 ms
8,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#coding: UTF-8

import sys
from math import pi
from collections import deque
from functools import reduce

### defs ###

### main ###
N,K = map(int,sys.stdin.readline().split())
S = sys.stdin.readline()[:N]

sz = len(S)
idx = [-1]*sz
stack = []
for i in range(sz):
	if(S[i]=='('):
		stack.append(i)
	else:
		hd = stack[-1]
		idx[i] = hd
		idx[hd] = i
		stack.pop()
print(idx[K-1]+1)
0