結果

問題 No.33 アメーバがたくさん
ユーザー バカらっくバカらっく
提出日時 2021-11-02 01:50:30
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 324 ms / 5,000 ms
コード長 1,353 bytes
コンパイル時間 15,094 ms
コンパイル使用メモリ 457,840 KB
実行使用メモリ 55,120 KB
最終ジャッジ日時 2024-04-19 04:41:46
合計ジャッジ時間 19,750 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 311 ms
54,880 KB
testcase_01 AC 307 ms
55,120 KB
testcase_02 AC 321 ms
55,116 KB
testcase_03 AC 321 ms
54,780 KB
testcase_04 AC 322 ms
54,852 KB
testcase_05 AC 324 ms
55,076 KB
testcase_06 AC 313 ms
54,952 KB
testcase_07 AC 307 ms
54,992 KB
testcase_08 AC 299 ms
54,704 KB
testcase_09 AC 298 ms
54,948 KB
testcase_10 AC 285 ms
51,516 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:2:10: warning: variable 'n' is never used
    val (n,d,t) = readLine()!!.split(" ").map { it.toInt() }
         ^
Main.kt:5:47: warning: name shadowed: n
    val ameba = readLine()!!.split(" ").map { n -> n.toLong().let { Ameba(it) } }.sorted()
                                              ^

ソースコード

diff #

fun main(args: Array<String>) {
    val (n,d,t) = readLine()!!.split(" ").map { it.toInt() }
    Ameba.d = d.toLong()
    Ameba.t = t.toLong()
    val ameba = readLine()!!.split(" ").map { n -> n.toLong().let { Ameba(it) } }.sorted()
    val amebaDic = mutableMapOf<Long,MutableList<Ameba>>()
    for(a in ameba) {
        if(!amebaDic.containsKey(a.group)) {
            amebaDic[a.group] = mutableListOf()
        }
        if(amebaDic[a.group]!!.isEmpty()) {
            amebaDic[a.group]!!.add(a)
        } else {
            if(amebaDic[a.group]!!.last().canUnion(a)) {
                amebaDic[a.group]!!.last().union(a)
            } else {
                amebaDic[a.group]!!.add(a)
            }
        }
    }
    val ans = amebaDic.values.map { list -> list.map { (it.to - it.from) / d + 1 }.sum() }.sum()
    println(ans)
}

class Ameba(init:Long):Comparable<Ameba> {
    companion object {
        var d = 0L
        var t = 0L
    }
    val group = (init%d + d)%d
    var from = init - d*t
    var to = init + d*t
    fun union(other:Ameba) {
        from = Math.min(from, other.from)
        to = Math.max(to, other.to)
    }
    fun canUnion(other: Ameba):Boolean {
        return (other.from in from..to) || (other.to in from..to)
    }

    override fun compareTo(other: Ameba): Int {
        return from.compareTo(other.from)
    }
}
0