結果
問題 |
No.33 アメーバがたくさん
|
ユーザー |
![]() |
提出日時 | 2021-11-02 01:50:30 |
言語 | Kotlin (2.1.0) |
結果 |
AC
|
実行時間 | 316 ms / 5,000 ms |
コード長 | 1,353 bytes |
コンパイル時間 | 14,953 ms |
コンパイル使用メモリ | 445,252 KB |
実行使用メモリ | 60,336 KB |
最終ジャッジ日時 | 2024-10-10 21:18:15 |
合計ジャッジ時間 | 19,611 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 |
コンパイルメッセージ
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() ^
ソースコード
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) } }