結果

問題 No.90 品物の並び替え
コンテスト
ユーザー komkomh
提出日時 2019-04-24 17:44:17
言語 Kotlin
(2.4.21 + ACL)
コンパイル:
kotlinc -cp /opt/aclib/ac_library.jar _filename_ -include-runtime -d main.jar
実行:
java -cp main.jar:/opt/aclib/ac_library.jar _class_
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,135 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 11,175 ms
コンパイル使用メモリ 506,524 KB
実行使用メモリ 53,076 KB
最終ジャッジ日時 2026-10-12 01:50:44
合計ジャッジ時間 31,864 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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