結果

問題 No.17 2つの地点に泊まりたい
コンテスト
ユーザー バカらっく
提出日時 2019-09-01 12:29:54
言語 Kotlin
(2.1.0)
結果
AC  
実行時間 482 ms / 5,000 ms
コード長 1,878 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 15,215 ms
コンパイル使用メモリ 485,796 KB
実行使用メモリ 62,884 KB
最終ジャッジ日時 2025-12-01 16:12:17
合計ジャッジ時間 27,029 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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