結果
問題 | No.1778 括弧列クエリ / Bracketed Sequence Query |
ユーザー | yudedako |
提出日時 | 2022-01-28 22:34:53 |
言語 | Scala(Beta) (3.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,017 bytes |
コンパイル時間 | 12,014 ms |
コンパイル使用メモリ | 244,776 KB |
実行使用メモリ | 123,892 KB |
最終ジャッジ日時 | 2023-08-28 20:52:08 |
合計ジャッジ時間 | 37,017 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | TLE | - |
testcase_02 | TLE | - |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | AC | 1,933 ms
84,972 KB |
testcase_07 | AC | 1,272 ms
67,040 KB |
testcase_08 | TLE | - |
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 | -- | - |
ソースコード
import scala.annotation.tailrec import scala.collection.{immutable, mutable} import scala.io.StdIn.readLine import scala.math.* import scala.annotation.tailrec @main def main = val Array(n, q) = readLine().split(' ').map(_.toInt) val s = readLine() val queries = Array.fill(q){ val Array(x, y) = readLine().split(' ').map(_.toInt - 1) min(x, y) -> max(x, y) } var stack = Nil: List[Int] val pair = Array.fill(n){-1} for (c, i) <- s.zipWithIndex do c match case '(' => stack ::= i case ')' => val h::t = stack pair(i) = h pair(h) = i stack = t val result = Array.fill(q){"-1"} val set = mutable.TreeSet[Int]() var last = 0 for ((x, y), i) <- queries.zipWithIndex.sortBy(_._1) do while last <= x do if s(last) == '(' then set.addOne(pair(last)) last += 1 set.minAfter(y) match case Some(right) => result(i) = s"${pair(right) + 1} ${right + 1}" case None => println( result.mkString("\n") )