結果

問題 No.19 ステージの選択
ユーザー バカらっくバカらっく
提出日時 2019-09-01 15:04:21
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,198 bytes
コンパイル時間 17,728 ms
コンパイル使用メモリ 423,964 KB
実行使用メモリ 55,688 KB
最終ジャッジ日時 2023-08-18 18:45:19
合計ジャッジ時間 23,095 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 272 ms
52,932 KB
testcase_01 AC 277 ms
53,036 KB
testcase_02 AC 266 ms
52,816 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 261 ms
53,248 KB
testcase_12 AC 269 ms
53,008 KB
testcase_13 AC 271 ms
53,016 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:2:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:19:51: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Map.Entry<Int, TreeNode>
        val cur = sublist.minBy { it.value.value }!!.value
                                                  ^

ソースコード

diff #

fun main(args: Array<String>) {
    val stageCount = readLine()!!.toInt()
    (1..stageCount).forEach {
        stageList[it] = TreeNode(it)
    }
    (1..stageCount).forEach {
        val (l, s) = readLine()!!.split(" ").map { it.toInt() }
        stageList[it]!!.value = l * 10
        stageList[it]!!.parent = stageList[s]!!
        stageList[s]!!.items.add(stageList[it]!!)
    }
    var ans = 0
    (1..stageCount).forEach {
        var sublist = stageList.filter {  it.value.parent == null && !it.value.clearFlag }
        if(sublist.isEmpty()) {
            sublist = stageList.filter { !it.value.clearFlag }
        }
        val cur = sublist.minBy { it.value.value }!!.value
        ans += cur.value
        cur.clearFlag = true
        cur.parent?.let {
            it.items.remove(cur)
        }
        cur.parent = null
        cur.items.forEach{
            it.value = it.value / 2
            it.parent = null
        }
        cur.items.clear()
    }
    println(ans.toDouble()/10)
}

val stageList = mutableMapOf<Int, TreeNode>()

class TreeNode(val id:Int) {
    var parent:TreeNode? = null
    var clearFlag = false
    var items = mutableListOf<TreeNode>()
    var value = 0
}
0