結果

問題 No.22 括弧の対応
ユーザー nagitaosunagitaosu
提出日時 2020-03-13 15:09:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 532 bytes
コンパイル時間 74 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 8,900 KB
最終ジャッジ日時 2023-09-27 13:45:31
合計ジャッジ時間 1,283 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,248 KB
testcase_01 AC 16 ms
8,112 KB
testcase_02 AC 17 ms
8,112 KB
testcase_03 AC 21 ms
8,828 KB
testcase_04 AC 18 ms
8,440 KB
testcase_05 AC 18 ms
8,448 KB
testcase_06 AC 19 ms
8,640 KB
testcase_07 AC 19 ms
8,792 KB
testcase_08 AC 19 ms
8,580 KB
testcase_09 AC 17 ms
8,472 KB
testcase_10 AC 19 ms
8,784 KB
testcase_11 AC 17 ms
8,492 KB
testcase_12 AC 19 ms
8,680 KB
testcase_13 AC 19 ms
8,836 KB
testcase_14 AC 16 ms
8,248 KB
testcase_15 AC 20 ms
8,900 KB
testcase_16 AC 19 ms
8,784 KB
testcase_17 AC 15 ms
8,232 KB
testcase_18 AC 16 ms
8,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
s = input().rstrip()
depth = [(0, 0)]
for ch in s:
    if ch == "(":
        depth.append((depth[-1][1], depth[-1][1] + 1))
    else:
        depth.append((depth[-1][1], depth[-1][1] - 1))
frm, too = depth[k]
if frm < too:
    for i in range(k, n+1):
        if depth[i] == (too, frm):
            print(i)
            exit()
else:
    for i in range(k, -1, -1):
        if depth[i] == (too, frm):
            print(i)
            exit()
0