結果

問題 No.17 2つの地点に泊まりたい
ユーザー バカらっくバカらっく
提出日時 2019-09-01 12:29:54
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 388 ms / 5,000 ms
コード長 1,878 bytes
コンパイル時間 18,341 ms
コンパイル使用メモリ 433,048 KB
実行使用メモリ 55,604 KB
最終ジャッジ日時 2023-08-18 14:52:50
合計ジャッジ時間 27,415 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 288 ms
52,788 KB
testcase_01 AC 290 ms
52,976 KB
testcase_02 AC 295 ms
54,940 KB
testcase_03 AC 344 ms
54,284 KB
testcase_04 AC 312 ms
53,192 KB
testcase_05 AC 365 ms
54,400 KB
testcase_06 AC 345 ms
53,396 KB
testcase_07 AC 333 ms
53,304 KB
testcase_08 AC 386 ms
54,976 KB
testcase_09 AC 388 ms
54,628 KB
testcase_10 AC 368 ms
54,628 KB
testcase_11 AC 382 ms
54,700 KB
testcase_12 AC 293 ms
53,076 KB
testcase_13 AC 287 ms
52,984 KB
testcase_14 AC 289 ms
52,936 KB
testcase_15 AC 293 ms
53,080 KB
testcase_16 AC 293 ms
53,164 KB
testcase_17 AC 303 ms
52,984 KB
testcase_18 AC 361 ms
55,604 KB
testcase_19 AC 322 ms
54,240 KB
testcase_20 AC 292 ms
53,124 KB
testcase_21 AC 292 ms
52,992 KB
testcase_22 AC 335 ms
54,316 KB
testcase_23 AC 362 ms
54,532 KB
testcase_24 AC 372 ms
54,628 KB
testcase_25 AC 295 ms
52,864 KB
testcase_26 AC 374 ms
54,732 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

fun main(args: Array<String>) {

    val pointCount = readLine()!!.toInt()
    road = arrayOfNulls(pointCount)
    for(i in 1..pointCount) {
        feeList.add(readLine()!!.toInt())
        road[i-1] = arrayOfNulls<Int>(pointCount)
        road[i-1]!![i-1] = 0
    }
    val roadCount = readLine()!!.toInt()
    for(i in 1..roadCount) {
        val (a,b,c) = readLine()!!.split(" ").map { it.toInt() }
        road[a]!![b] = c
        road[b]!![a] = c
    }
    for(i in road.indices) {
        for(j in road.indices) {
            for(k in road.indices) {
                val express = road[j]!![k]
                road[j]!![i]?.let {
                    val part1 = it
                    road[i]!![k]?.let {
                        val part2 = it
                        express?.also {
                            if(express > part1 + part2) {
                                road[j]!![k] = part1 + part2
                            }
                        } ?: run {
                            road[j]!![k] = part1 + part2
                        }

                    }
                }
            }
        }
    }

    var ans = feeList.sum() + road.map { it!!.filter { it != null }.map { it!!.toLong() }.sum() }.sum()
    for(i in 1..pointCount - 2) {
        if(road[0]!![i] == null) {
            continue
        }
        for(j in 1..pointCount - 2) {
            if(i == j) {
                continue
            }
            if(road[i]!![j] == null) {
                continue
            }
            if(road[j]!![pointCount-1] == null) {
                continue
            }
            val subTotal = road[0]!![i]!! + feeList[i] + road[i]!![j]!! + feeList[j] + road[j]!![pointCount-1]!!
            ans = Math.min(ans, subTotal.toLong())
        }
    }
    println(ans)
}

var feeList = mutableListOf<Int>()
var road = arrayOfNulls<Array<Int?>>(0)
0