結果
問題 | No.120 傾向と対策:門松列(その1) |
ユーザー | バカらっく |
提出日時 | 2019-10-02 09:32:00 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 1,662 ms / 5,000 ms |
コード長 | 770 bytes |
コンパイル時間 | 13,637 ms |
コンパイル使用メモリ | 445,276 KB |
実行使用メモリ | 104,916 KB |
最終ジャッジ日時 | 2024-04-14 08:51:14 |
合計ジャッジ時間 | 20,745 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,212 ms
99,332 KB |
testcase_01 | AC | 1,508 ms
102,112 KB |
testcase_02 | AC | 977 ms
98,728 KB |
testcase_03 | AC | 1,662 ms
104,916 KB |
コンパイルメッセージ
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 }