結果
問題 | No.22 括弧の対応 |
ユーザー | kashiwagi513 |
提出日時 | 2019-02-23 20:57:57 |
言語 | Python3 (3.11.6 + numpy 1.26.0 + scipy 1.11.3) |
結果 |
AC
|
実行時間 | 195 ms / 5,000 ms |
コード長 | 757 bytes |
コンパイル時間 | 219 ms |
コンパイル使用メモリ | 10,804 KB |
実行使用メモリ | 10,332 KB |
最終ジャッジ日時 | 2023-09-27 13:35:09 |
合計ジャッジ時間 | 2,649 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
8,984 KB |
testcase_01 | AC | 20 ms
8,968 KB |
testcase_02 | AC | 20 ms
9,044 KB |
testcase_03 | AC | 186 ms
10,332 KB |
testcase_04 | AC | 58 ms
9,508 KB |
testcase_05 | AC | 48 ms
9,492 KB |
testcase_06 | AC | 126 ms
9,896 KB |
testcase_07 | AC | 85 ms
9,984 KB |
testcase_08 | AC | 40 ms
9,864 KB |
testcase_09 | AC | 88 ms
9,628 KB |
testcase_10 | AC | 56 ms
10,108 KB |
testcase_11 | AC | 47 ms
9,448 KB |
testcase_12 | AC | 97 ms
9,760 KB |
testcase_13 | AC | 195 ms
10,016 KB |
testcase_14 | AC | 24 ms
9,280 KB |
testcase_15 | AC | 155 ms
10,224 KB |
testcase_16 | AC | 190 ms
10,240 KB |
testcase_17 | AC | 22 ms
9,092 KB |
testcase_18 | AC | 20 ms
8,948 KB |
ソースコード
# -*- coding: utf-8 -*- from queue import LifoQueue def index(l): return l[0] def value(l): return l[1] def match(l, r): return value(l) == '(' and value(r) == ')' def reduce(ls, goal): ls = ls stack = LifoQueue() while len(ls) >= 2: hd, hd_, rest = ls[0], ls[1], ls[2:] if match(hd, hd_): if index(hd) == goal: return index(hd_) if index(hd_) == goal: return index(hd) ls = [stack.get()] + rest if not stack.empty() else rest else: stack.put(hd) ls = [hd_] + rest def solve(n, k, s): ls = [(i+1, c) for i, c in enumerate(s)] print(reduce(ls, k)) n, k = input().split() s = input() solve(int(n), int(k), s)