結果

問題 No.247 線形計画問題もどき
コンテスト
ユーザー くわい
提出日時 2015-10-28 00:05:04
言語 Scala(Beta)
(3.8.1)
コンパイル:
scalac _filename_
実行:
java -cp .:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala3-library_3/3.8.1/scala3-library_3-3.8.1.jar:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala-library/3.8.1/scala-library-3.8.1.jar _class_
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 998 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,361 ms
コンパイル使用メモリ 234,160 KB
最終ジャッジ日時 2026-03-09 14:08:53
合計ジャッジ時間 6,714 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
-- [E040] Syntax Error: Main.scala:39:32 ---------------------------------------
39 |  def main(args: Array[String]) {
   |                                ^
   |                                '=' expected, but '{' found
-- Warning: Main.scala:16:58 ---------------------------------------------------
16 |    val q = new mutable.PriorityQueue[State]()(Ordering.by(_.count))
   |                                               ^^^^^^^^^^^^^^^^^^^^
   |Implicit parameters should be provided with a `using` clause.
   |This code can be rewritten automatically under -rewrite -source 3.7-migration.
   |To disable the warning, please use the following option:
   |  "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"
1 warning found
1 error found

ソースコード

diff #
raw source code

import java.util.Scanner

import scala.collection.mutable

object Problem247 {

  case class State(count: Int, total: Int)

  def proc(total: Int, n: Int, ai: Seq[Int]): Int = {
    if (total % ai.max == 0) {
      return total / ai.max
    }

    val dp = Array.fill(total + 1)(Int.MaxValue)

    val q = new mutable.PriorityQueue[State]()(Ordering.by(_.count))
    q += State(0, 0)

    while (!q.isEmpty) {
      val s = q.dequeue()

      for (a <- ai) {
        if (s.total + a <= total) {
          val next = State(s.count + 1, s.total + a)
          if (next.count < dp(next.total)) {
            q += next
            dp(next.total) = next.count
          }
        }
      }
    }

    dp(total) match {
      case Int.MaxValue => -1
      case x => x
    }
  }

  def main(args: Array[String]) {
    val sc = new Scanner(System.in)
    val total = sc.nextInt()
    val n = sc.nextInt()
    val ai = Seq.fill(n)(sc.nextInt())
    val result = proc(total, n, ai)
    println(result)
  }
}
0