結果

問題 No.733 分身並列コーディング
ユーザー kajikaji
提出日時 2018-09-22 02:15:01
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 1,385 bytes
コンパイル時間 13,128 ms
コンパイル使用メモリ 448,940 KB
実行使用メモリ 117,160 KB
最終ジャッジ日時 2024-04-30 19:13:58
合計ジャッジ時間 18,101 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 369 ms
64,852 KB
testcase_01 AC 370 ms
99,624 KB
testcase_02 AC 365 ms
68,460 KB
testcase_03 AC 402 ms
61,340 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 scanner = Scanner(System.`in`)
    
    val T = scanner.nextInt()
    val N = scanner.nextInt()

    val times = (1..N).map { scanner.nextInt() }.sortedDescending().toMutableList()
    val combinationsCache = mutableMapOf<Int, List<MutableList<Int>>>()
    var count = 0

    for (t in T downTo 1) {
        for (i in 1..t) {
            generateSequence {
                combinationsCache
                        .getOrPut(i) { times.combinations(i) }
                        .find { it.sum() == t }
            }.forEach { c ->
                c.forEach { times.remove(it) }
                combinationsCache.clear()
                ++count

                if (times.size == 0) {
                    println(count)
                    return
                }
            }
        }
    }
}

fun <T> List<T>.combinations(n: Int): List<MutableList<T>> {
    return when {
        n > size -> emptyList()
        n == 1 -> map { mutableListOf(it) }
        else -> {
            val last = size
            (0 until last).fold(emptyList()) { all, index -> 
                all + subList(index + 1, last)
                        .combinations(n - 1)
                        .map { 
                            it.add(0, get(index)) 
                            it 
                        } 
            }
        }
    }
}
0