結果

問題 No.22 括弧の対応
ユーザー a_tena_ten
提出日時 2016-03-15 20:53:21
言語 Python2
(2.7.18)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 338 bytes
コンパイル時間 53 ms
コンパイル使用メモリ 6,640 KB
実行使用メモリ 6,116 KB
最終ジャッジ日時 2023-09-27 13:02:35
合計ジャッジ時間 1,011 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
5,932 KB
testcase_01 AC 10 ms
5,856 KB
testcase_02 AC 9 ms
5,848 KB
testcase_03 AC 9 ms
5,924 KB
testcase_04 AC 10 ms
5,920 KB
testcase_05 AC 9 ms
5,968 KB
testcase_06 AC 9 ms
5,884 KB
testcase_07 AC 10 ms
5,860 KB
testcase_08 AC 10 ms
5,852 KB
testcase_09 AC 9 ms
5,852 KB
testcase_10 AC 10 ms
5,964 KB
testcase_11 AC 10 ms
5,888 KB
testcase_12 AC 10 ms
5,952 KB
testcase_13 AC 10 ms
5,880 KB
testcase_14 AC 10 ms
5,980 KB
testcase_15 AC 9 ms
5,920 KB
testcase_16 AC 9 ms
5,928 KB
testcase_17 AC 9 ms
5,968 KB
testcase_18 AC 9 ms
6,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#coding:utf-8

N,K=map(int,raw_input().split())
S=raw_input()

cnt,ans=0,0

if S[K-1] == '(':	
	for i in S[K-1:]:
		cnt+=1
		if i == '(':
			ans+=1
		else:
			ans-=1
			if ans == 0:
				print cnt+(K-1)
				break
else:
	for i in S[:K][::-1]:
		cnt+=1
		if i == ')':
			ans+=1
		else:
			ans-=1
			if ans == 0:
				print K-(cnt-1)
				break
0