結果

問題 No.90 品物の並び替え
ユーザー komkomhkomkomh
提出日時 2019-04-24 17:44:17
言語 Kotlin
(1.9.23)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,135 bytes
コンパイル時間 13,630 ms
コンパイル使用メモリ 419,476 KB
実行使用メモリ 61,844 KB
最終ジャッジ日時 2023-08-13 01:50:36
合計ジャッジ時間 25,207 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 317 ms
56,988 KB
testcase_01 AC 820 ms
61,400 KB
testcase_02 AC 325 ms
56,952 KB
testcase_03 AC 441 ms
61,392 KB
testcase_04 AC 454 ms
61,568 KB
testcase_05 AC 863 ms
61,844 KB
testcase_06 AC 713 ms
61,612 KB
testcase_07 AC 436 ms
61,340 KB
testcase_08 AC 323 ms
56,904 KB
testcase_09 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder

fun main() {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    val itemScores = (0 until m).map {
        val (item1, item2, score) = readLine()!!.split(" ").map(String::toInt)
        Triple(item1, item2, score)
    }

    fun getScore(items: IntArray): Int {
        var score = 0
        for (i in 0 until itemScores.size) {
            val item = itemScores[i]
            if (items.indexOf(item.first) < items.indexOf(item.second)) {
                score += item.third
            }
        }
        return score
    }

    fun getMaxScore(vararg items: Int): Int {
        return when (items.size >= n) {
            true -> getScore(items)
            false -> {
                var maxScore = 0
                for (i in 0..n) {
                    if (items.contains(i)) {
                        continue
                    }
                    val score = getMaxScore(*items, i)
                    if (maxScore < score) {
                        maxScore = score
                    }
                }
                maxScore
            }
        }
    }
    println(getMaxScore())
}
0