結果

問題 No.22 括弧の対応
ユーザー kashiwagi513kashiwagi513
提出日時 2019-02-23 17:36:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 596 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 10,784 KB
実行使用メモリ 9,808 KB
最終ジャッジ日時 2023-08-20 11:51:17
合計ジャッジ時間 1,553 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,944 KB
testcase_01 AC 15 ms
7,772 KB
testcase_02 AC 15 ms
7,856 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 15 ms
7,764 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def match(l, r):
    if l[1] == '(' and r[1] == ')': return True
    else: return False

def reduce(hd, rest, goal):
#    print(str(hd) + ", " + str(rest))
    if match(hd, rest[0]):
        if hd[0] == goal:
            print(rest[0][0])
        if rest[0][0] == goal:
            print(hd[0])
        return rest[1:]
    else:
        rest_ = reduce(rest[0], rest[1:], goal)
        return reduce(hd, rest_, goal)

def solve(n, k, s):
    ls = [(i+1, c) for i, c in enumerate(s)]
    reduce(ls[0], ls[1:], k)

n, k = input().split()
s = input()
solve(int(n), int(k), s)
0