結果

問題 No.1 道のショートカット
ユーザー くわいくわい
提出日時 2015-11-05 14:41:57
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,348 ms / 5,000 ms
コード長 1,531 bytes
コンパイル時間 10,417 ms
コンパイル使用メモリ 257,456 KB
実行使用メモリ 73,544 KB
最終ジャッジ日時 2023-09-02 06:41:39
合計ジャッジ時間 64,629 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,034 ms
64,176 KB
testcase_01 AC 1,032 ms
64,140 KB
testcase_02 AC 1,029 ms
64,240 KB
testcase_03 AC 1,048 ms
64,424 KB
testcase_04 AC 1,020 ms
64,084 KB
testcase_05 AC 1,046 ms
64,116 KB
testcase_06 AC 1,046 ms
64,324 KB
testcase_07 AC 1,050 ms
64,380 KB
testcase_08 AC 1,226 ms
64,468 KB
testcase_09 AC 1,210 ms
64,632 KB
testcase_10 AC 1,228 ms
64,444 KB
testcase_11 AC 1,239 ms
64,352 KB
testcase_12 AC 1,312 ms
72,308 KB
testcase_13 AC 1,283 ms
72,728 KB
testcase_14 AC 1,046 ms
64,652 KB
testcase_15 AC 1,037 ms
64,468 KB
testcase_16 AC 1,126 ms
64,412 KB
testcase_17 AC 1,055 ms
64,400 KB
testcase_18 AC 1,089 ms
64,200 KB
testcase_19 AC 1,084 ms
64,304 KB
testcase_20 AC 1,117 ms
64,312 KB
testcase_21 AC 1,109 ms
64,788 KB
testcase_22 AC 1,064 ms
64,388 KB
testcase_23 AC 1,348 ms
72,484 KB
testcase_24 AC 1,236 ms
64,328 KB
testcase_25 AC 1,156 ms
64,188 KB
testcase_26 AC 1,101 ms
64,500 KB
testcase_27 AC 1,266 ms
64,508 KB
testcase_28 AC 1,048 ms
64,312 KB
testcase_29 AC 1,329 ms
73,544 KB
testcase_30 AC 1,114 ms
64,156 KB
testcase_31 AC 1,177 ms
64,756 KB
testcase_32 AC 1,191 ms
64,772 KB
testcase_33 AC 1,159 ms
64,308 KB
testcase_34 AC 1,230 ms
64,632 KB
testcase_35 AC 1,198 ms
64,728 KB
testcase_36 AC 1,218 ms
64,416 KB
testcase_37 AC 1,203 ms
64,480 KB
testcase_38 AC 1,066 ms
64,076 KB
testcase_39 AC 1,106 ms
64,268 KB
testcase_40 AC 1,141 ms
64,376 KB
testcase_41 AC 1,130 ms
64,212 KB
testcase_42 AC 1,044 ms
64,224 KB
testcase_43 AC 1,043 ms
64,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner

import scala.collection.mutable

object Problem001 {

  case class Route(start: Int, to: Int, cost: Int, dist: Int)

  case class State(currentCity: Int, totalCost: Int, totalDist: Int)

  def proc(cityCount: Int, costLimit: Int, routeCount: Int,
           start: IndexedSeq[Int], to: IndexedSeq[Int], costs: IndexedSeq[Int], dists: IndexedSeq[Int]): Int = {

    // 町から出る道のリスト
    val routes: Map[Int, Seq[Route]] = ((0 until routeCount) map { i =>
      Route(start(i), to(i), costs(i), dists(i))
    }).groupBy(x => x.start)

    def f: (State) => Int = x => x.totalDist
    val queue = new mutable.PriorityQueue[State]()(Ordering.by(f).reverse)

    // 開始地点設定
    queue += State(1, 0, 0)

    while (queue.nonEmpty) {
      val s: State = queue.dequeue()

      if (s.currentCity == cityCount) {
        return s.totalDist
      }

      for (route <- routes.getOrElse(s.currentCity, Seq())) {
        if (s.totalCost + route.cost <= costLimit) {
          queue += State(route.to, s.totalCost + route.cost, s.totalDist + route.dist)
        }
      }
    }

    -1
  }

  def main(args: Array[String]) = {
    val sc = new Scanner(System.in)
    val N = sc.nextInt()
    val C = sc.nextInt()
    val V = sc.nextInt()
    val S = IndexedSeq.fill(V)(sc.nextInt())
    val T = IndexedSeq.fill(V)(sc.nextInt())
    val Y = IndexedSeq.fill(V)(sc.nextInt())
    val M = IndexedSeq.fill(V)(sc.nextInt())

    val result = proc(N, C, V, S, T, Y, M)
    println(result)
  }
}
0