結果

問題 No.22 括弧の対応
ユーザー 👑 yumechiyumechi
提出日時 2015-04-10 12:49:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 555 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,768 KB
実行使用メモリ 8,876 KB
最終ジャッジ日時 2023-09-27 12:50:49
合計ジャッジ時間 1,430 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,784 KB
testcase_01 AC 15 ms
7,908 KB
testcase_02 AC 16 ms
7,728 KB
testcase_03 AC 26 ms
8,876 KB
testcase_04 AC 20 ms
8,220 KB
testcase_05 AC 19 ms
8,204 KB
testcase_06 AC 21 ms
8,420 KB
testcase_07 AC 22 ms
8,768 KB
testcase_08 AC 20 ms
8,576 KB
testcase_09 AC 20 ms
8,304 KB
testcase_10 AC 22 ms
8,668 KB
testcase_11 AC 18 ms
8,204 KB
testcase_12 AC 21 ms
8,532 KB
testcase_13 AC 23 ms
8,808 KB
testcase_14 AC 17 ms
7,712 KB
testcase_15 AC 24 ms
8,840 KB
testcase_16 AC 23 ms
8,840 KB
testcase_17 AC 15 ms
7,724 KB
testcase_18 AC 15 ms
7,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
S = input()
leftcounter = rightcounter = 0
llist, rlist, list = [], [], []
for i in range(N):
    if S[i] == "(":
        leftcounter += 1
        llist.append(i + 1)
    if S[i] == ")":
        rightcounter += 1
        rlist.append(i + 1)
        if leftcounter >= rightcounter:
            l = llist.pop()
            r = rlist.pop()
            list.append([l, r])

for i in range(2):
    for j in range(len(list)):
        if list[j][i] == K:
            print(list[j][1] if i == 0 else list[j][0])
            break
0