結果

問題 No.124 門松列(3)
ユーザー バカらっくバカらっく
提出日時 2019-10-02 11:24:11
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 3,018 ms / 5,000 ms
コード長 2,390 bytes
コンパイル時間 15,182 ms
コンパイル使用メモリ 461,324 KB
実行使用メモリ 149,280 KB
最終ジャッジ日時 2024-04-14 08:53:00
合計ジャッジ時間 46,147 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,018 ms
149,280 KB
testcase_01 AC 345 ms
60,668 KB
testcase_02 AC 348 ms
60,760 KB
testcase_03 AC 2,893 ms
130,056 KB
testcase_04 AC 445 ms
63,008 KB
testcase_05 AC 435 ms
62,848 KB
testcase_06 AC 348 ms
60,624 KB
testcase_07 AC 341 ms
60,580 KB
testcase_08 AC 338 ms
60,572 KB
testcase_09 AC 340 ms
60,588 KB
testcase_10 AC 347 ms
60,568 KB
testcase_11 AC 341 ms
60,520 KB
testcase_12 AC 339 ms
60,532 KB
testcase_13 AC 342 ms
60,724 KB
testcase_14 AC 368 ms
60,852 KB
testcase_15 AC 397 ms
63,112 KB
testcase_16 AC 2,902 ms
146,504 KB
testcase_17 AC 406 ms
63,216 KB
testcase_18 AC 372 ms
60,828 KB
testcase_19 AC 2,836 ms
123,924 KB
testcase_20 AC 2,877 ms
142,496 KB
testcase_21 AC 407 ms
63,172 KB
testcase_22 AC 2,828 ms
123,720 KB
testcase_23 AC 384 ms
62,944 KB
testcase_24 AC 408 ms
63,056 KB
testcase_25 AC 408 ms
62,868 KB
testcase_26 AC 368 ms
60,800 KB
testcase_27 AC 357 ms
60,664 KB
testcase_28 AC 438 ms
62,816 KB
testcase_29 AC 447 ms
63,176 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'args' is never used
fun main(args:Array<String>) {
         ^
Main.kt:51:115: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Map.Entry<Int, Int>
        var ans = dic[dic.lastIndex].let { it[it.lastIndex] }.let { if(it.isEmpty()) -1 else it.minBy { it.value }!!.value }
                                                                                                                  ^

ソースコード

diff #

import java.util.*

fun main(args:Array<String>) {
    val (w,h) = readLine()!!.split(" ").map { it.toInt() }
    Proc(w, h).getAns()
}

class Proc(val w:Int, val h:Int) {
    val map = (0 until h).map { a-> readLine()!!.split(" ").withIndex().map { b-> Pos(b.index, a, b.value.toInt(), w) } }
    val dic = (0 until h).map { (0 until w).map { mutableMapOf<Int, Int>() } }
    public fun getAns() {
        val queue = LinkedList<Task>()
        queue.push(Task(map[0][0], null, 0))
        while (queue.isNotEmpty()) {
            val t = queue.pop()
            val prevKey = t.prev?.let { it.index }?:-1
            if(dic[t.current.y][t.current.x].containsKey(prevKey) && dic[t.current.y][t.current.x][prevKey]!! <= t.step) {
                continue
            }
            dic[t.current.y][t.current.x][prevKey] = t.step
            for(i in (t.current.y - 1..t.current.y + 1)) {
                if(i < 0 || i > map.lastIndex) {
                    continue
                }
                for(j in (t.current.x - 1.. t.current.x + 1)) {
                    if(j < 0 || j > map[i].lastIndex) {
                        continue
                    }
                    if(i == t.current.y && j == t.current.x) {
                        continue
                    }
                    if(i != t.current.y && j != t.current.x) {
                        continue
                    }
                    if(t.prev != null) {
                        if(i == t.prev.y && j == t.prev.x) {
                            continue
                        }
                        val tmp = listOf(t.prev.z, t.current.z, map[i][j].z)
                        if(tmp.distinct().size != 3) {
                            continue
                        }
                        if(tmp.max() != tmp[1] && tmp.min() != tmp[1]) {
                            continue
                        }
                    }
                    queue.push(Task(map[i][j], t.current, t.step + 1))
                }
            }
        }
        var ans = dic[dic.lastIndex].let { it[it.lastIndex] }.let { if(it.isEmpty()) -1 else it.minBy { it.value }!!.value }
        if(ans <= 0) {
            ans = -1
        }
        println(ans)
    }
    class Pos(val x:Int, val y:Int, val z:Int, val w:Int) {
        val index = y * w + x
    }
    class Task(val current:Pos, val prev:Pos?, val step:Int)
}
0