結果

問題 No.22 括弧の対応
ユーザー yoshi_kyoshi_k
提出日時 2017-09-19 00:32:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 759 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,828 KB
実行使用メモリ 8,824 KB
最終ジャッジ日時 2023-09-27 13:19:16
合計ジャッジ時間 1,318 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,032 KB
testcase_01 AC 16 ms
7,976 KB
testcase_02 AC 15 ms
8,004 KB
testcase_03 AC 29 ms
8,824 KB
testcase_04 AC 21 ms
8,424 KB
testcase_05 AC 21 ms
8,528 KB
testcase_06 AC 24 ms
8,472 KB
testcase_07 AC 25 ms
8,672 KB
testcase_08 AC 21 ms
8,376 KB
testcase_09 AC 20 ms
8,552 KB
testcase_10 AC 23 ms
8,652 KB
testcase_11 AC 19 ms
8,416 KB
testcase_12 AC 22 ms
8,456 KB
testcase_13 AC 23 ms
8,628 KB
testcase_14 AC 15 ms
8,288 KB
testcase_15 AC 28 ms
8,652 KB
testcase_16 AC 26 ms
8,652 KB
testcase_17 AC 15 ms
8,288 KB
testcase_18 AC 15 ms
8,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

try:
    import mydebug

    def dprint(*objects, sep='', end='\n'):
        print(*objects)
except:
    def dprint(*objects, sep='', end='\n'): pass

n, k = [int(x) for x in input().split()]
s = input().rstrip()

stc = []
pairs = []
dprint(s)
state = ""
dprint("len(s)",len(s))
for i in range(len(s)):
    dprint("-----", i+1, s[i])
    if s[i] == "(":
        dprint("append", i+1)
        stc.append(i+1)
        state += "("
        dprint(state)
    else:
        state = state[:-1]
        dprint(state)
        dprint("pop", stc[-1])
        pairs.append((i+1, stc[-1]))
        stc.pop()

def other(t, n):
    if t[0] == n:
        return t[1]
    else:
        return t[0]

for p in pairs:
    if k in p:
        dprint(p)
        print(other(p, k))
0