結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 890 ms
22,668 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 15 ms
8,216 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 15 ms
8,248 KB
testcase_22 AC 14 ms
8,180 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 1,227 ms
60,340 KB
testcase_27 AC 1,020 ms
54,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def int_input():
    return map(int,input().split())
n, q = int_input()
s = input()

qs = [tuple(int_input()) for _ in range(q)]

pairs_b = [()] * (n + 1)
pairs_t = [()] * (n + 1)
singles = []

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

def ret_pairs(x):
    if len(pairs_b[x]) != 0:
        return pairs_b[x]
    else:
        return pairs_t[x]

def find_min_including_set(qs):
    x = ret_pairs(qs[0])
    y = ret_pairs(qs[1])
    bottom = min(x[0], y[0])
    top = max(x[1], y[1])
    for i in range(bottom):
        j = bottom - i
        candidate = pairs_b[j]
        if candidate[1] >= top:
            return candidate

for i in qs:
    ans = find_min_including_set(i)
    if ans:
        print(*ans)
    else:
        print(-1)
0