結果
問題 |
No.19 ステージの選択
|
ユーザー |
![]() |
提出日時 | 2019-09-01 15:04:21 |
言語 | Kotlin (2.1.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,198 bytes |
コンパイル時間 | 14,387 ms |
コンパイル使用メモリ | 444,876 KB |
実行使用メモリ | 57,336 KB |
最終ジャッジ日時 | 2024-11-28 01:59:00 |
合計ジャッジ時間 | 22,878 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 6 WA * 18 |
コンパイルメッセージ
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 ^
ソースコード
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 }