結果
問題 | No.1778 括弧列クエリ / Bracketed Sequence Query |
ユーザー | Wizist |
提出日時 | 2021-12-11 18:00:53 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 486 bytes |
コンパイル時間 | 260 ms |
コンパイル使用メモリ | 87,156 KB |
実行使用メモリ | 93,044 KB |
最終ジャッジ日時 | 2023-09-27 06:18:29 |
合計ジャッジ時間 | 28,698 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | TLE | - |
testcase_14 | WA | - |
testcase_15 | AC | 64 ms
71,452 KB |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
ソースコード
from bisect import bisect_left N, Q = map(int, input().split()) s = input().strip() p = [0] * N st = [] for i, x in enumerate(s): if x == '(': st.append(i) else: p[i] = st[-1] p[st[-1]] = i st.pop() a = [(i, p[i]) for i, x in enumerate(s) if x == '('] for _ in range(Q): x, y = map(int, input().split()) x -= 1; y -= 1 i = bisect_left(a, (x, y)) while i >= 0: if a[i][0] <= x and a[i][1] >= y: break i -= 1 if i < 0: print(-1) else: print(a[i][0] + 1, a[i][1] + 1)