結果
| 問題 | No.1 道のショートカット |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-11-05 14:41:57 |
| 言語 | Scala(Beta) (3.8.1) |
| 結果 |
AC
|
| 実行時間 | 752 ms / 5,000 ms |
| コード長 | 1,531 bytes |
| 記録 | |
| コンパイル時間 | 10,811 ms |
| コンパイル使用メモリ | 286,164 KB |
| 実行使用メモリ | 71,824 KB |
| 最終ジャッジ日時 | 2026-03-09 14:15:27 |
| 合計ジャッジ時間 | 37,982 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
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)
}
}