結果

問題 No.4 おもりと天秤
ユーザー rutilicusrutilicus
提出日時 2020-08-31 23:17:38
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 401 ms / 5,000 ms
コード長 667 bytes
コンパイル時間 15,282 ms
コンパイル使用メモリ 426,736 KB
実行使用メモリ 68,632 KB
最終ジャッジ日時 2023-08-10 18:05:16
合計ジャッジ時間 23,660 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 282 ms
52,976 KB
testcase_01 AC 283 ms
52,948 KB
testcase_02 AC 281 ms
52,916 KB
testcase_03 AC 278 ms
52,920 KB
testcase_04 AC 298 ms
53,256 KB
testcase_05 AC 380 ms
62,492 KB
testcase_06 AC 280 ms
53,196 KB
testcase_07 AC 395 ms
68,632 KB
testcase_08 AC 275 ms
52,848 KB
testcase_09 AC 307 ms
53,424 KB
testcase_10 AC 400 ms
68,592 KB
testcase_11 AC 268 ms
53,096 KB
testcase_12 AC 274 ms
52,856 KB
testcase_13 AC 280 ms
53,316 KB
testcase_14 AC 273 ms
52,992 KB
testcase_15 AC 283 ms
52,920 KB
testcase_16 AC 288 ms
53,124 KB
testcase_17 AC 290 ms
52,852 KB
testcase_18 AC 395 ms
56,260 KB
testcase_19 AC 401 ms
62,544 KB
testcase_20 AC 396 ms
62,380 KB
testcase_21 AC 398 ms
62,488 KB
testcase_22 AC 396 ms
62,460 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:27:13: warning: 'appendln(String?): kotlin.text.StringBuilder /* = java.lang.StringBuilder */' is deprecated. Use appendLine instead. Note that the new method always appends the line feed character '\n' regardless of the system line separator.
    builder.appendln(if (dp[n - 1].contains(sum / 2)) "possible" else "impossible")
            ^

ソースコード

diff #

fun main() {
    val builder = StringBuilder()

    val n = readInputLine().toInt()

    val wArr = readInputLine().split(" ").map { it.toInt() }

    val sum = wArr.sum()

    if (sum % 2 == 1) {
        println("impossible")
        return
    }

    val dp = Array(n) { mutableSetOf<Int>() }

    dp[0].add(0)
    dp[0].add(wArr[0])

    for (i in 1 until wArr.size) {
        dp[i].addAll(dp[i - 1])
        for (prev in dp[i - 1]) {
            dp[i].add(prev + wArr[i])
        }
    }

    builder.appendln(if (dp[n - 1].contains(sum / 2)) "possible" else "impossible")

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}
0