結果

問題 No.22 括弧の対応
ユーザー 🍡yurahuna
提出日時 2016-01-21 01:50:46
言語 Python2
(2.7.18)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 272 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2024-07-20 07:07:31
合計ジャッジ時間 891 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, raw_input().split())
s = raw_input()
dx = 1  #left to right
if s[K-1] == ')':
    dx = -1
i = K-1
cnt = 1 #(num of same bracket as s[K-1]) - (not same)
while cnt != 0:
    i += dx
    if s[i] == s[K-1]:
        cnt += 1
    else:
        cnt -= 1
print i+1
0