結果

問題 No.1826 Fruits Collecting
ユーザー yudedakoyudedako
提出日時 2022-01-31 16:05:39
言語 Scala(Beta)
(3.4.0)
結果
TLE  
実行時間 -
コード長 1,717 bytes
コンパイル時間 10,396 ms
コンパイル使用メモリ 257,012 KB
実行使用メモリ 107,900 KB
最終ジャッジ日時 2023-09-02 02:14:49
合計ジャッジ時間 43,332 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 943 ms
62,836 KB
testcase_01 AC 1,005 ms
62,672 KB
testcase_02 AC 997 ms
62,768 KB
testcase_03 AC 1,021 ms
62,640 KB
testcase_04 AC 938 ms
62,708 KB
testcase_05 AC 1,819 ms
79,180 KB
testcase_06 TLE -
testcase_07 AC 1,913 ms
76,324 KB
testcase_08 AC 1,296 ms
63,128 KB
testcase_09 TLE -
testcase_10 AC 1,867 ms
78,628 KB
testcase_11 AC 1,843 ms
81,016 KB
testcase_12 AC 1,461 ms
67,916 KB
testcase_13 AC 1,374 ms
66,772 KB
testcase_14 AC 1,424 ms
65,944 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 880 ms
62,456 KB
testcase_26 AC 875 ms
62,280 KB
testcase_27 AC 877 ms
63,668 KB
testcase_28 AC 878 ms
62,516 KB
testcase_29 AC 909 ms
62,672 KB
testcase_30 AC 1,504 ms
68,036 KB
testcase_31 AC 1,853 ms
78,624 KB
testcase_32 AC 1,555 ms
69,520 KB
testcase_33 TLE -
testcase_34 TLE -
testcase_35 AC 1,484 ms
65,940 KB
testcase_36 TLE -
testcase_37 AC 1,970 ms
79,620 KB
testcase_38 AC 1,796 ms
78,912 KB
testcase_39 AC 1,628 ms
78,932 KB
testcase_40 AC 1,702 ms
92,208 KB
testcase_41 AC 1,323 ms
65,968 KB
testcase_42 AC 1,080 ms
63,204 KB
testcase_43 AC 900 ms
62,508 KB
testcase_44 AC 887 ms
62,560 KB
testcase_45 AC 889 ms
62,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)



0