結果

問題 No.22 括弧の対応
ユーザー irisAsh
提出日時 2024-05-06 18:57:59
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 226 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-11-29 04:20:36
合計ジャッジ時間 1,766 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int, input().split())
S=input()
if S[K-1]=='(':
    a=S[K:]
    c=')'
    p=1
else:
    a=S[:(K-1)][::-1]
    c='('
    p=-1
w=1
n=0
for x in a:
    n+=p
    w+=(-1 if x==c else 1)
    if w==0:
        break
print(n+K)
0