結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 966 ms
22,576 KB
testcase_01 AC 956 ms
22,528 KB
testcase_02 AC 968 ms
22,468 KB
testcase_03 AC 864 ms
22,448 KB
testcase_04 AC 1,112 ms
22,440 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])
    for i in range(bottom):
        j = bottom - i
        candidate = pairs[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