結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,047 ms
26,752 KB
testcase_01 AC 1,024 ms
22,428 KB
testcase_02 AC 1,046 ms
22,556 KB
testcase_03 AC 968 ms
22,716 KB
testcase_04 AC 1,294 ms
22,332 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()

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

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])
    dis_b = bottom
    dis_t = n + 1 - top
    dis = min(dis_b, dis_t)
    for i in range(dis):
        j = bottom - i
        candidate_b = pairs[j]
        if candidate_b[1] >= top:
            return candidate_b
        k = top + i
        candidate_t = pairs[k]
        if candidate_t[0] <= bottom:
            return candidate_t

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

    
0