結果

問題 No.22 括弧の対応
ユーザー あかりき
提出日時 2021-02-08 08:18:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 315 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 52,736 KB
最終ジャッジ日時 2024-07-05 04:48:26
合計ジャッジ時間 1,752 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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