結果
問題 | No.34 砂漠の行商人 |
ユーザー |
![]() |
提出日時 | 2019-09-07 15:49:51 |
言語 | Kotlin (2.1.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,697 bytes |
コンパイル時間 | 14,356 ms |
コンパイル使用メモリ | 454,144 KB |
実行使用メモリ | 316,872 KB |
最終ジャッジ日時 | 2024-06-26 20:49:08 |
合計ジャッジ時間 | 25,625 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 9 TLE * 1 -- * 16 |
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'arr' is never used fun main(arr:Array<String>) { ^ Main.kt:52:40: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Int ans = step[gy][gx].values.min()!! ^
ソースコード
import java.util.* fun main(arr:Array<String>) { val inpt = readLine()!!.trim().split(" ").map { it.toInt() } val (n, v) = inpt.take(2) val (sx, sy, gx, gy) = inpt.drop(2).map { it - 1 } val map = (1..n).map { readLine()!!.split(" ").map { it.toInt() }.toTypedArray() }.toTypedArray() val step = map.map { it.map { mutableMapOf<Int, Int>() }.toTypedArray() }.toTypedArray() val queue = ArrayDeque<Task>() var min = n * n + 1 queue.add(Task(sx, sy, v, 0)) while (queue.isNotEmpty()) { val t = queue.pop() if(t.vital <= 0) { continue } if(t.step > min) { continue } var skip = false step[t.y][t.x][t.vital]?.also { if(it <= t.step) { skip = true } } if(skip) { continue } else { step[t.y][t.x][t.vital] = t.step } if(t.x == gx && t.y == gy) { min = Math.min(min, t.step) continue } if(t.y > 0) { queue.add(Task(t.x, t.y - 1, t.vital - map[t.y - 1][t.x], t.step + 1)) } if(t.y < n - 1) { queue.add(Task(t.x, t.y + 1, t.vital - map[t.y + 1][t.x], t.step + 1)) } if(t.x > 0) { queue.add(Task(t.x - 1, t.y, t.vital - map[t.y][t.x - 1], t.step + 1)) } if(t.x < n - 1) { queue.add(Task(t.x + 1, t.y, t.vital - map[t.y][t.x + 1], t.step + 1)) } } var ans = -1 if(step[gy][gx].isNotEmpty()) { ans = step[gy][gx].values.min()!! } println(ans) } data class Task(val x:Int, val y:Int, val vital:Int, val step:Int)