結果
問題 | No.1826 Fruits Collecting |
ユーザー | yudedako |
提出日時 | 2022-01-31 16:08:20 |
言語 | Scala(Beta) (3.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,482 bytes |
コンパイル時間 | 9,746 ms |
コンパイル使用メモリ | 268,348 KB |
実行使用メモリ | 102,288 KB |
最終ジャッジ日時 | 2024-06-11 08:55:54 |
合計ジャッジ時間 | 45,419 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 878 ms
63,704 KB |
testcase_01 | AC | 925 ms
63,792 KB |
testcase_02 | AC | 950 ms
64,004 KB |
testcase_03 | AC | 934 ms
63,928 KB |
testcase_04 | AC | 870 ms
63,984 KB |
testcase_05 | AC | 1,673 ms
80,656 KB |
testcase_06 | TLE | - |
testcase_07 | AC | 1,684 ms
79,392 KB |
testcase_08 | AC | 1,204 ms
65,920 KB |
testcase_09 | AC | 1,983 ms
94,740 KB |
testcase_10 | AC | 1,734 ms
82,052 KB |
testcase_11 | AC | 1,690 ms
77,632 KB |
testcase_12 | AC | 1,422 ms
68,588 KB |
testcase_13 | AC | 1,251 ms
66,264 KB |
testcase_14 | AC | 1,294 ms
67,532 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 | 836 ms
63,452 KB |
testcase_26 | AC | 833 ms
63,472 KB |
testcase_27 | AC | 827 ms
63,380 KB |
testcase_28 | AC | 835 ms
63,692 KB |
testcase_29 | AC | 820 ms
63,604 KB |
testcase_30 | AC | 1,380 ms
69,160 KB |
testcase_31 | AC | 1,765 ms
82,156 KB |
testcase_32 | AC | 1,411 ms
70,124 KB |
testcase_33 | TLE | - |
testcase_34 | AC | 1,902 ms
84,920 KB |
testcase_35 | AC | 1,361 ms
67,816 KB |
testcase_36 | TLE | - |
testcase_37 | AC | 1,833 ms
82,784 KB |
testcase_38 | AC | 1,617 ms
79,776 KB |
testcase_39 | AC | 1,553 ms
82,840 KB |
testcase_40 | AC | 1,586 ms
92,540 KB |
testcase_41 | AC | 1,256 ms
67,980 KB |
testcase_42 | AC | 1,339 ms
64,172 KB |
testcase_43 | AC | 971 ms
63,624 KB |
testcase_44 | AC | 814 ms
63,456 KB |
testcase_45 | AC | 806 ms
63,628 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.* class BinaryIndexedTree(val size: Int): private val vec = Array.fill(size){0L} def get(position: Int): Long = var result = 0L var pos = position while vec.indices.contains(pos) do result = max(result, vec(pos)) pos -= ~pos & (pos + 1) result def add(position: Int, value: Long): Unit = var pos = position while vec.indices.contains(pos) do vec(pos) = max(vec(pos), value) pos += ~pos & (pos + 1) def getAll(): Long = 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(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)