結果

問題 No.33 アメーバがたくさん
ユーザー バカらっくバカらっく
提出日時 2019-09-07 13:36:36
言語 Kotlin
(1.9.10)
結果
AC  
実行時間 311 ms / 5,000 ms
コード長 1,046 bytes
コンパイル時間 16,836 ms
コンパイル使用メモリ 431,596 KB
実行使用メモリ 57,312 KB
最終ジャッジ日時 2023-09-08 16:07:14
合計ジャッジ時間 19,791 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 303 ms
57,116 KB
testcase_01 AC 303 ms
57,152 KB
testcase_02 AC 306 ms
57,264 KB
testcase_03 AC 304 ms
56,928 KB
testcase_04 AC 306 ms
56,972 KB
testcase_05 AC 304 ms
57,312 KB
testcase_06 AC 306 ms
56,912 KB
testcase_07 AC 305 ms
57,164 KB
testcase_08 AC 308 ms
57,288 KB
testcase_09 AC 311 ms
56,980 KB
testcase_10 AC 292 ms
53,172 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