結果

問題 No.1778 括弧列クエリ / Bracketed Sequence Query
ユーザー SchneeSchnee
提出日時 2021-12-07 02:39:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 913 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 25,688 KB
最終ジャッジ日時 2023-09-21 16:30:08
合計ジャッジ時間 13,719 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,484 ms
15,564 KB
testcase_01 AC 1,492 ms
8,388 KB
testcase_02 AC 1,520 ms
8,280 KB
testcase_03 AC 1,431 ms
8,272 KB
testcase_04 AC 1,650 ms
8,336 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def int_input():
    return map(int,input().split())

n, q = int_input()
s = input()

pairs = {}
singles = []

for i in range(n):
    if s[i] == "(":
        singles.append(i)
    else:
        a = singles.pop(-1) + 1
        pairs[a] = (a, i + 1)
        pairs[i + 1] = (a, i + 1)

def find_min_including_set(qs):
    x = pairs[qs[0]]
    y = pairs[qs[1]]
    bottom = min(x[0], y[0])
    top = max(x[1], y[1])
    if bottom < n + 1 - top:
        for i in range(bottom):
            j = bottom - i
            candidate = pairs[j]
            if candidate[1] >= top:
                return candidate
    else:
        for i in range(n + 1 - top):
            k = top + i
            candidate = pairs[k]
            if candidate[0] <= bottom:
                return candidate

for _ in range(q):
    i = tuple(int_input())
    if ans := find_min_including_set(i):
        print(*ans)
    else:
        print(-1)
0