結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー バカらっくバカらっく
提出日時 2019-10-02 03:31:56
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 720 bytes
コンパイル時間 13,676 ms
コンパイル使用メモリ 447,824 KB
実行使用メモリ 100,076 KB
最終ジャッジ日時 2024-04-14 08:46:22
合計ジャッジ時間 19,698 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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()
        ^

ソースコード

diff #

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()
    val 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)
            }
        }
        ans++
    }
    return ans
}

0