結果

問題 No.22 括弧の対応
ユーザー wholekeikwholekeik
提出日時 2017-06-18 10:14:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 401 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-09 19:22:59
合計ジャッジ時間 1,558 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 31 ms
10,752 KB
testcase_08 RE -
testcase_09 AC 30 ms
10,752 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 30 ms
10,752 KB
testcase_13 AC 30 ms
10,752 KB
testcase_14 AC 30 ms
10,752 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = list(map(int, input().split()))
S = input()

result = 0
k = K - 1

if S[k] == '(':
	nesing = 0
	for i in range(k, N):
		if S[i] == '(':
			nesting += 1
		else:
			nesting -= 1
			if nesting == 0:
				result = i + 1
				break
else:
	nesting = 0
	for i in range(k, -1, -1):
		if S[i] == '(':
			nesting -= 1
			if nesting == 0:
				result = i + 1
				break
		else:
			nesting += 1


print(result)
0