結果
問題 | No.1778 括弧列クエリ / Bracketed Sequence Query |
ユーザー |
![]() |
提出日時 | 2021-12-07 02:20:14 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 707 bytes |
コンパイル時間 | 140 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 45,304 KB |
最終ジャッジ日時 | 2024-07-07 10:11:08 |
合計ジャッジ時間 | 10,727 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 1 |
other | AC * 5 TLE * 1 -- * 21 |
ソースコード
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)