結果

問題 No.22 括弧の対応
ユーザー pluto77pluto77
提出日時 2016-02-29 08:35:31
言語 Python2
(2.7.18)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 379 bytes
コンパイル時間 71 ms
コンパイル使用メモリ 6,680 KB
実行使用メモリ 6,052 KB
最終ジャッジ日時 2023-09-27 13:02:28
合計ジャッジ時間 1,017 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
5,916 KB
testcase_01 AC 11 ms
6,040 KB
testcase_02 AC 9 ms
5,916 KB
testcase_03 AC 9 ms
5,844 KB
testcase_04 AC 9 ms
5,892 KB
testcase_05 AC 9 ms
5,844 KB
testcase_06 AC 10 ms
5,920 KB
testcase_07 AC 10 ms
5,912 KB
testcase_08 AC 10 ms
6,052 KB
testcase_09 AC 9 ms
5,844 KB
testcase_10 AC 9 ms
5,860 KB
testcase_11 AC 9 ms
5,980 KB
testcase_12 AC 9 ms
5,848 KB
testcase_13 AC 9 ms
5,932 KB
testcase_14 AC 9 ms
5,848 KB
testcase_15 AC 9 ms
5,944 KB
testcase_16 AC 9 ms
5,856 KB
testcase_17 AC 9 ms
6,040 KB
testcase_18 AC 9 ms
5,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#coding: utf-8
##yuki_22


nk=map(int,raw_input().split())
s=raw_input()

n=nk[0]
k=nk[1]
k=k-1
count=0

if s[k]=='(':
 for i in xrange(k,n):
  if s[i]=='(':
   count+=1
  elif s[i]==')':
   count-=1
  if count==0:
   rt=i
   break
elif s[k]==')':
 for i in xrange(k,-1,-1):  
  if s[i]==')':
   count+=1
  elif s[i]=='(':
   count-=1
  if count==0:
   rt=i
   break

print rt+1
0