結果

問題 No.92 逃走経路
ユーザー バカらっくバカらっく
提出日時 2019-09-28 06:51:12
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 980 ms / 5,000 ms
コード長 1,618 bytes
コンパイル時間 15,955 ms
コンパイル使用メモリ 453,888 KB
実行使用メモリ 66,368 KB
最終ジャッジ日時 2024-04-08 13:59:48
合計ジャッジ時間 30,999 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 825 ms
66,368 KB
testcase_01 AC 329 ms
54,596 KB
testcase_02 AC 341 ms
58,744 KB
testcase_03 AC 350 ms
58,772 KB
testcase_04 AC 353 ms
58,788 KB
testcase_05 AC 445 ms
59,280 KB
testcase_06 AC 455 ms
59,536 KB
testcase_07 AC 456 ms
59,524 KB
testcase_08 AC 393 ms
58,932 KB
testcase_09 AC 980 ms
64,812 KB
testcase_10 AC 823 ms
65,736 KB
testcase_11 AC 866 ms
65,816 KB
testcase_12 AC 888 ms
66,072 KB
testcase_13 AC 683 ms
65,924 KB
testcase_14 AC 707 ms
65,828 KB
testcase_15 AC 766 ms
65,876 KB
testcase_16 AC 775 ms
65,140 KB
testcase_17 AC 774 ms
66,132 KB
testcase_18 AC 716 ms
66,028 KB
testcase_19 AC 622 ms
64,680 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:4:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
         ^
Main.kt:5:9: warning: variable 'cityCount' is never used
    val(cityCount, roadCount, logCount) = readLine()!!.split(" ").map { it.toInt() }
        ^
Main.kt:5:31: warning: variable 'logCount' is never used
    val(cityCount, roadCount, logCount) = readLine()!!.split(" ").map { it.toInt() }
                              ^

ソースコード

diff #

import kotlin.math.PI


fun main(arr:Array<String>) {
    val(cityCount, roadCount, logCount) = readLine()!!.split(" ").map { it.toInt() }
    val roads = mutableMapOf<Int,MutableMap<Int, MutableMap<Long, Boolean>>>()
    (0 until roadCount).forEach {
        val(city1, city2, cost) = readLine()!!.split(" ").map { it.toInt() }
        if(!roads.containsKey(city1)) {
            roads[city1] = mutableMapOf()
        }
        if(!roads.containsKey(city2)) {
            roads[city2] = mutableMapOf()
        }
        if(!roads[city1]!!.containsKey(city2)) {
            roads[city1]!![city2] = mutableMapOf()
        }
        if(!roads[city2]!!.containsKey(city1)) {
            roads[city2]!![city1] = mutableMapOf()
        }

        roads[city1]!![city2]!![cost.toLong()] = true
        roads[city2]!![city1]!![cost.toLong()] = true
    }

    val log = readLine()!!.split(" ").map { it.toLong() }
    val ans = Proc(roads, log).getAns()
    println(ans.size)
    println(ans.sorted().joinToString(" "))
}

class Proc(val roads:Map<Int, Map<Int,Map<Long, Boolean>>>, val log:List<Long>) {
    public fun getAns():List<Int> {


        var currentList = roads.map { a->a.value.filter { b-> log[0] in b.value.keys }.map { it.key }.toMutableList() }.reduce { acc, list -> acc.union(list).toMutableList() }.toList()
        for(i in log.drop(1)) {
            currentList = currentList.map { a->roads[a]?.let { b-> b.filter { i in it.value.keys }.keys.toMutableList() }?: mutableListOf() }.reduce { acc, mutableList -> acc.union(mutableList).toMutableList() }.toList()
        }
        return currentList
    }
}
0