結果
問題 |
No.124 門松列(3)
|
ユーザー |
![]() |
提出日時 | 2021-11-10 11:46:26 |
言語 | Kotlin (2.1.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,859 bytes |
コンパイル時間 | 15,935 ms |
コンパイル使用メモリ | 459,372 KB |
実行使用メモリ | 63,056 KB |
最終ジャッジ日時 | 2024-11-20 21:37:46 |
合計ジャッジ時間 | 28,874 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 25 WA * 1 |
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'args' is never used fun main(args: Array<String>) { ^
ソースコード
import java.util.* fun main(args: Array<String>) { val (w, h) = readLine()!!.split(" ").map { it.toInt() } val map = (1..h).map { readLine()!!.split(" ").map { it.toInt() } } val step = Array(h){ Array(w) { mutableMapOf<Int?, Step>() } } val queue = LinkedList<Pos>() queue.add(Pos(0,0)) step[0][0][null] = Step(0, null) while (queue.isNotEmpty()) { val cur = queue.pop() step[cur.r][cur.c].values.forEach { s -> val next = listOf(Pos(cur.r-1, cur.c), Pos(cur.r+1, cur.c), Pos(cur.r, cur.c-1), Pos(cur.r, cur.c+1)) for(n in next) { if(n.r !in map.indices) { continue } if(n.c !in map[n.r].indices) { continue } if(step[n.r][n.c][map[cur.r][cur.c]]?.step?:200 <= s.step + 1) { continue } if(s.prev == map[n.r][n.c]) { continue } if(map[cur.r][cur.c] == map[n.r][n.c]) { continue } var isValid = false s.prev?.let { prev -> val list = listOf(prev, map[cur.r][cur.c], map[n.r][n.c]).sorted() map[cur.r][cur.c].let { if(list[0] == it || list[2] == it) { isValid = true } } }?: run { isValid = true } if(isValid) { step[n.r][n.c][map[cur.r][cur.c]] = Step(s.step + 1, map[cur.r][cur.c]) queue.add(n) } } } } println(step.last().last().values.firstOrNull()?.step?:-1) } data class Step(val step:Int, val prev:Int?) data class Pos(val r:Int, val c:Int)