結果

問題 No.22 括弧の対応
ユーザー magurogumamaguroguma
提出日時 2017-08-12 22:13:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 480 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 10,704 KB
実行使用メモリ 8,668 KB
最終ジャッジ日時 2023-09-27 13:18:27
合計ジャッジ時間 1,220 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,500 KB
testcase_01 AC 17 ms
8,456 KB
testcase_02 AC 16 ms
8,536 KB
testcase_03 AC 17 ms
8,484 KB
testcase_04 AC 16 ms
8,536 KB
testcase_05 AC 18 ms
8,528 KB
testcase_06 AC 20 ms
8,584 KB
testcase_07 AC 16 ms
8,608 KB
testcase_08 AC 16 ms
8,532 KB
testcase_09 AC 18 ms
8,508 KB
testcase_10 AC 16 ms
8,452 KB
testcase_11 AC 16 ms
8,444 KB
testcase_12 AC 18 ms
8,448 KB
testcase_13 AC 20 ms
8,668 KB
testcase_14 AC 16 ms
8,596 KB
testcase_15 AC 18 ms
8,468 KB
testcase_16 AC 19 ms
8,480 KB
testcase_17 AC 17 ms
8,436 KB
testcase_18 AC 16 ms
8,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

from collections import deque

class paren:
    def __init__(self, char, id):
        self.char = char
        self.id = id

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

parentheses = deque()

for (c,i) in zip(S, range(1, len(S)+1)):
    p = paren(c,i)
    if len(parentheses)==0 or c=='(':
        parentheses.append(p)
    else:
        q = parentheses.pop()
        if p.id==K or q.id==K:
            print(q.id if p.id==K else p.id)
            break
0