結果

問題 No.22 括弧の対応
ユーザー mlihua09mlihua09
提出日時 2020-08-27 15:15:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 70 ms / 5,000 ms
コード長 729 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 71,288 KB
最終ジャッジ日時 2023-09-27 13:50:22
合計ジャッジ時間 2,426 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
70,840 KB
testcase_01 AC 70 ms
70,912 KB
testcase_02 AC 63 ms
71,104 KB
testcase_03 AC 66 ms
71,288 KB
testcase_04 AC 63 ms
71,004 KB
testcase_05 AC 64 ms
70,996 KB
testcase_06 AC 67 ms
71,232 KB
testcase_07 AC 66 ms
71,160 KB
testcase_08 AC 69 ms
71,100 KB
testcase_09 AC 62 ms
71,204 KB
testcase_10 AC 67 ms
71,040 KB
testcase_11 AC 65 ms
71,040 KB
testcase_12 AC 64 ms
70,920 KB
testcase_13 AC 65 ms
71,164 KB
testcase_14 AC 66 ms
70,944 KB
testcase_15 AC 66 ms
70,952 KB
testcase_16 AC 68 ms
71,172 KB
testcase_17 AC 65 ms
71,196 KB
testcase_18 AC 63 ms
71,008 KB
権限があれば一括ダウンロードができます

ソースコード

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