結果

問題 No.22 括弧の対応
ユーザー a_tena_ten
提出日時 2016-03-15 20:27:55
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 338 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 14:09:13
合計ジャッジ時間 1,177 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,548 KB
testcase_01 AC 11 ms
6,548 KB
testcase_02 AC 11 ms
6,548 KB
testcase_03 AC 11 ms
6,548 KB
testcase_04 AC 11 ms
6,548 KB
testcase_05 AC 11 ms
6,548 KB
testcase_06 AC 11 ms
6,548 KB
testcase_07 WA -
testcase_08 AC 11 ms
6,548 KB
testcase_09 WA -
testcase_10 AC 11 ms
6,548 KB
testcase_11 AC 12 ms
6,548 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 11 ms
6,548 KB
testcase_16 AC 12 ms
6,548 KB
testcase_17 AC 11 ms
6,548 KB
testcase_18 AC 11 ms
6,548 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 cnt-(K-1)
				break
0