結果

問題 No.22 括弧の対応
ユーザー mlihua09mlihua09
提出日時 2020-08-27 15:15:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 43 ms / 5,000 ms
コード長 729 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,172 KB
実行使用メモリ 53,300 KB
最終ジャッジ日時 2024-07-20 07:52:15
合計ジャッジ時間 1,696 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #


N, K = map(int, input().split())

S = input()

x = 0


if S[K - 1] == '(':
    
    for i in range(K, N):
        
        if S[i] == ')':
            
            if x == 0:
                
                print(i + 1)
                break
                
            else:
                
                x -= 1
                
        else:
            
            x += 1
            
else:
    
    for i in range(K - 2, -1, -1):
        
        if S[i] == '(':
            
            if x == 0:
                
                print(i + 1)
                
                break
            
            else:
                
                x -= 1
                
        else:
            
            x += 1
0