結果

問題 No.22 括弧の対応
ユーザー あかりきあかりき
提出日時 2021-02-08 08:18:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 78 ms / 5,000 ms
コード長 315 bytes
コンパイル時間 359 ms
コンパイル使用メモリ 87,308 KB
実行使用メモリ 71,556 KB
最終ジャッジ日時 2023-09-18 13:44:40
合計ジャッジ時間 2,859 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,444 KB
testcase_01 AC 75 ms
71,496 KB
testcase_02 AC 74 ms
71,360 KB
testcase_03 AC 78 ms
71,464 KB
testcase_04 AC 74 ms
71,192 KB
testcase_05 AC 74 ms
71,164 KB
testcase_06 AC 74 ms
71,556 KB
testcase_07 AC 77 ms
71,404 KB
testcase_08 AC 76 ms
71,548 KB
testcase_09 AC 75 ms
71,228 KB
testcase_10 AC 76 ms
71,548 KB
testcase_11 AC 76 ms
71,484 KB
testcase_12 AC 75 ms
71,368 KB
testcase_13 AC 73 ms
71,368 KB
testcase_14 AC 73 ms
71,180 KB
testcase_15 AC 73 ms
71,232 KB
testcase_16 AC 75 ms
71,364 KB
testcase_17 AC 76 ms
71,308 KB
testcase_18 AC 75 ms
71,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k=map(int,input().split())
s=list(input())
ct=1
if s[k-1]=='(':
  for i in range(k,n):
    if s[i]==')':
      ct-=1
    else:
      ct+=1
    if ct==0:
      print(i+1)
      exit()
else:
  for i in range(k-2,-1,-1):
    if s[i]=='(':
      ct-=1
    else:
      ct+=1
    if ct==0:
      print(i+1)
      exit()
0