結果

問題 No.33 アメーバがたくさん
ユーザー バカらっくバカらっく
提出日時 2019-09-07 13:31:13
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,045 bytes
コンパイル時間 16,493 ms
コンパイル使用メモリ 425,300 KB
実行使用メモリ 57,276 KB
最終ジャッジ日時 2023-09-08 15:59:56
合計ジャッジ時間 21,159 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 304 ms
56,744 KB
testcase_01 AC 306 ms
56,916 KB
testcase_02 AC 303 ms
56,932 KB
testcase_03 WA -
testcase_04 AC 306 ms
57,276 KB
testcase_05 WA -
testcase_06 AC 308 ms
56,708 KB
testcase_07 AC 308 ms
57,132 KB
testcase_08 AC 306 ms
56,852 KB
testcase_09 WA -
testcase_10 AC 290 ms
52,664 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
         ^
Main.kt:4:10: warning: variable 'amebaCount' is never used
    val (amebaCount, move, totalTime) = readLine()!!.split(" ").map { it.toInt() }
         ^
Main.kt:6:45: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Ameba
    val minPos = amebaList.minBy { it.from }!!.from
                                            ^

ソースコード

diff #

import java.util.*

fun main(arr:Array<String>) {
    val (amebaCount, move, totalTime) = readLine()!!.split(" ").map { it.toInt() }
    val amebaList = readLine()!!.split(" ").map { Ameba(it.toLong() - move.toLong() * totalTime, it.toLong() + move.toLong() * totalTime) }.sortedBy { it.from }.toMutableList()
    val minPos = amebaList.minBy { it.from }!!.from
    val amebaMap = mutableMapOf<Long, MutableList<Ameba>>()
    amebaList.map { (it.from - minPos) % move }.distinct().forEach { amebaMap[it] = mutableListOf() }
    var ans = 0.toLong()
    amebaMap.forEach {
        val key = it.key
        val list = amebaList.filter { (it.from - minPos) % move == key }.sortedBy { it.from }.toMutableList()
        for(i in list.lastIndex downTo 1) {
            if(list[i-1].to > list[i].from) {
                list[i-1] = Ameba(list[i-1].from, list[i].to)
                list.removeAt(i)
            }
        }
        ans += list.map { (it.to - it.from) / move + 1 }.sum()
    }
    println(ans)
}

class Ameba(var from:Long, var to:Long)
0