結果
| 問題 | 
                            No.33 アメーバがたくさん
                             | 
                    
| コンテスト | |
| ユーザー | 
                             バカらっく
                         | 
                    
| 提出日時 | 2019-09-07 13:36:36 | 
| 言語 | Kotlin  (2.1.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 332 ms / 5,000 ms | 
| コード長 | 1,046 bytes | 
| コンパイル時間 | 14,857 ms | 
| コンパイル使用メモリ | 459,504 KB | 
| 実行使用メモリ | 60,580 KB | 
| 最終ジャッジ日時 | 2024-06-26 09:06:21 | 
| 合計ジャッジ時間 | 17,907 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 11 | 
コンパイルメッセージ
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
                                            ^
            
            ソースコード
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)
            
            
            
        
            
バカらっく