結果

問題 No.22 括弧の対応
ユーザー ABKZABKZ
提出日時 2021-10-03 23:20:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 76 ms / 5,000 ms
コード長 483 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 86,944 KB
実行使用メモリ 71,568 KB
最終ジャッジ日時 2023-09-29 02:11:51
合計ジャッジ時間 3,365 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,360 KB
testcase_01 AC 74 ms
71,380 KB
testcase_02 AC 75 ms
71,480 KB
testcase_03 AC 75 ms
71,352 KB
testcase_04 AC 75 ms
71,280 KB
testcase_05 AC 76 ms
71,396 KB
testcase_06 AC 75 ms
71,124 KB
testcase_07 AC 75 ms
71,460 KB
testcase_08 AC 75 ms
71,248 KB
testcase_09 AC 75 ms
71,212 KB
testcase_10 AC 74 ms
71,236 KB
testcase_11 AC 74 ms
71,256 KB
testcase_12 AC 76 ms
71,424 KB
testcase_13 AC 75 ms
71,348 KB
testcase_14 AC 74 ms
71,120 KB
testcase_15 AC 75 ms
71,264 KB
testcase_16 AC 74 ms
71,336 KB
testcase_17 AC 75 ms
71,100 KB
testcase_18 AC 75 ms
71,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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