結果
問題 | No.1826 Fruits Collecting |
ユーザー | yudedako |
提出日時 | 2022-01-31 16:04:46 |
言語 | Scala(Beta) (3.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,712 bytes |
コンパイル時間 | 11,609 ms |
コンパイル使用メモリ | 264,344 KB |
実行使用メモリ | 103,836 KB |
最終ジャッジ日時 | 2024-06-11 08:52:39 |
合計ジャッジ時間 | 48,833 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | TLE | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | TLE | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | AC | 837 ms
63,444 KB |
testcase_26 | AC | 840 ms
63,292 KB |
testcase_27 | AC | 829 ms
63,556 KB |
testcase_28 | AC | 869 ms
63,696 KB |
testcase_29 | AC | 844 ms
63,668 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | TLE | - |
testcase_34 | TLE | - |
testcase_35 | WA | - |
testcase_36 | TLE | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 836 ms
63,412 KB |
testcase_44 | AC | 826 ms
63,348 KB |
testcase_45 | AC | 830 ms
63,656 KB |
ソースコード
import scala.collection.mutable import scala.collection.mutable.ArrayBuffer import scala.io.StdIn.* import scala.math.* import scala.reflect.ClassTag import scala.util.chaining.* trait Monoid[T]: val zero: T def plus(left: T, right: T): T inline given Monoid[Int] with override val zero = 0 override def plus(left: Int, right: Int) = max(left, right) class BinaryIndexedTree[T : ClassTag](val size: Int)(using m: Monoid[T]): export m.* private val vec = Array.fill(size){zero} def get(position: Int): T = var result = zero var pos = position while vec.indices.contains(pos) do result = plus(result, vec(pos)) pos -= ~pos & (pos + 1) result def add(position: Int, value: T): Unit = var pos = position while vec.indices.contains(pos) do vec(pos) = plus(vec(pos), value) pos += ~pos & (pos + 1) def getAll(): T = get(size - 1) extension (array: Array[Int]) def lowerBound(value: Int): Int = var min = 0 var max = array.length while min < max do val mid = (min + max) >>> 1 if array(mid) < value then min = mid + 1 else max = mid max @main def main = val n = readLine().toInt val fruits = Array.fill(n){ val Array(t, x, v) = readLine().split(' ').map(_.toInt) (t, x, v) } val diff = fruits.map{(t, x, _) => t - x}.distinct.sorted val bit = BinaryIndexedTree[Int](diff.length) for (t, x, v) <- fruits.sorted(using Ordering.by[(Int, Int, Int), Int]{(t, x, _) => t + x}.orElseBy{(t, _, _) => t}) do if t >= abs(x) then val di = diff.lowerBound(t - x) val maxValue = bit.get(di) + v bit.add(di, maxValue) val result = bit.getAll() println(result)