結果

問題 No.22 括弧の対応
ユーザー a_ten
提出日時 2016-03-15 20:53:21
言語 Python2
(2.7.18)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 338 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2024-07-20 07:09:49
合計ジャッジ時間 1,168 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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