結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2019-10-02 09:32:00 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 1,457 ms / 5,000 ms |
| コード長 | 770 bytes |
| コンパイル時間 | 14,922 ms |
| コンパイル使用メモリ | 450,044 KB |
| 実行使用メモリ | 104,176 KB |
| 最終ジャッジ日時 | 2024-10-03 05:55:09 |
| 合計ジャッジ時間 | 16,843 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
^
Main.kt:7:9: warning: variable 'itemCount' is never used
val itemCount = readLine()!!.toInt()
^
ソースコード
fun main(arr:Array<String>) {
val testcaseCount = readLine()!!.toInt()
(1..testcaseCount).forEach { println(getAns()) }
}
fun getAns():Int {
val itemCount = readLine()!!.toInt()
val items = readLine()!!.split(" ").map { it.toInt() }.let { a-> a.toSet().map { b-> b to a.count { it == b } }}.toMap().toMutableMap()
var keys = items.keys.sortedByDescending { items[it]!! }.toMutableList()
var ans = 0
while (items.size >= 3) {
for(i in (0 until 3).reversed()) {
items[keys[i]] = items[keys[i]]!! - 1
if(items[keys[i]]!! == 0) {
items.remove(keys[i])
keys.removeAt(i)
}
keys.sortByDescending { items[it]!! }
}
ans++
}
return ans
}
バカらっく