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