結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 12 ms
6,548 KB
testcase_05 AC 12 ms
6,548 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 10 ms
6,548 KB
testcase_09 WA -
testcase_10 AC 11 ms
6,548 KB
testcase_11 AC 11 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 13 ms
6,548 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#coding:utf-8

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

cnt_l,ans_l=0,0
cnt_r,ans_r=0,0

if K <= len(S)/2:	
	for i in S[K-1:]:
		cnt_l+=1
		if i == S[K-1]:
			ans_l+=1
		else:
			ans_l-=1
			if ans_l == 0:
				print cnt_l+(K-1)
				break
else:
	for i in S[:K][::-1]:
		cnt_r+=1
		if i == S[K-1]:
			ans_r+=1
		else:
			ans_r-=1
			if ans_r == 0:
				print cnt_r-(K-1)
				break
0