結果
問題 | No.1826 Fruits Collecting |
ユーザー | yudedako |
提出日時 | 2022-01-31 16:05:39 |
言語 | Scala(Beta) (3.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,717 bytes |
コンパイル時間 | 10,894 ms |
コンパイル使用メモリ | 269,544 KB |
実行使用メモリ | 104,872 KB |
最終ジャッジ日時 | 2024-06-11 08:54:11 |
合計ジャッジ時間 | 42,589 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 854 ms
63,852 KB |
testcase_01 | AC | 958 ms
63,804 KB |
testcase_02 | AC | 895 ms
63,908 KB |
testcase_03 | AC | 940 ms
63,836 KB |
testcase_04 | AC | 844 ms
63,740 KB |
testcase_05 | AC | 1,802 ms
81,656 KB |
testcase_06 | TLE | - |
testcase_07 | AC | 1,770 ms
80,100 KB |
testcase_08 | AC | 1,141 ms
65,360 KB |
testcase_09 | TLE | - |
testcase_10 | AC | 1,704 ms
82,212 KB |
testcase_11 | AC | 1,683 ms
78,148 KB |
testcase_12 | AC | 1,388 ms
68,800 KB |
testcase_13 | AC | 1,227 ms
66,312 KB |
testcase_14 | AC | 1,306 ms
67,480 KB |
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 | 778 ms
63,348 KB |
testcase_26 | AC | 795 ms
63,320 KB |
testcase_27 | AC | 800 ms
63,468 KB |
testcase_28 | AC | 789 ms
63,492 KB |
testcase_29 | AC | 789 ms
63,408 KB |
testcase_30 | AC | 1,382 ms
69,340 KB |
testcase_31 | AC | 1,695 ms
81,772 KB |
testcase_32 | AC | 1,455 ms
70,408 KB |
testcase_33 | TLE | - |
testcase_34 | AC | 1,975 ms
85,176 KB |
testcase_35 | AC | 1,303 ms
68,024 KB |
testcase_36 | TLE | - |
testcase_37 | TLE | - |
testcase_38 | AC | 1,622 ms
80,272 KB |
testcase_39 | AC | 1,551 ms
84,500 KB |
testcase_40 | AC | 1,618 ms
94,088 KB |
testcase_41 | AC | 1,202 ms
68,164 KB |
testcase_42 | AC | 970 ms
64,288 KB |
testcase_43 | AC | 809 ms
63,552 KB |
testcase_44 | AC | 785 ms
63,512 KB |
testcase_45 | AC | 829 ms
63,556 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[Long] with override val zero = 0L override def plus(left: Long, right: Long) = 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[Long](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)