結果

問題 No.29 パワーアップ
ユーザー バカらっくバカらっく
提出日時 2019-09-06 08:24:43
言語 Kotlin
(1.9.23)
結果
RE  
実行時間 -
コード長 828 bytes
コンパイル時間 13,985 ms
コンパイル使用メモリ 422,556 KB
実行使用メモリ 55,672 KB
最終ジャッジ日時 2023-09-05 17:45:39
合計ジャッジ時間 23,040 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 314 ms
53,132 KB
testcase_01 AC 313 ms
53,160 KB
testcase_02 AC 310 ms
53,152 KB
testcase_03 AC 314 ms
53,000 KB
testcase_04 AC 302 ms
53,096 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 336 ms
53,656 KB
testcase_08 AC 339 ms
53,432 KB
testcase_09 AC 305 ms
53,264 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 312 ms
53,044 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 340 ms
53,484 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 311 ms
52,852 KB
testcase_21 AC 308 ms
53,128 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

import java.util.*

fun main(args: Array<String>) {
    val count = readLine()!!.toInt()
    var items = mutableListOf<Int>()
    (1..count).forEach { items.addAll(readLine()!!.split(" ").map { it.toInt() }) }
    var ans = 0
    while (items.size >= 2) {
        items.sortWith(kotlin.Comparator { a, b -> comp(a,b,items) })
        val (a,b) = items.take(2)
        if(a == b) {
            ans++
            (0..1).forEach { items.removeAt(0) }
        } else if(items.size >= 4) {
            ans = ans + items.size / 4
            break
        } else {
            break
        }
    }
    println(ans)
}
fun comp(a:Int, b:Int, list : List<Int>):Int {
    val num1 = list.count { it == a }
    val num2 = list.count { it == b }
    if(num1 == num2) {
        return a.compareTo(b)
    }
    return num2.compareTo(num1)
}
0