結果

問題 No.4 おもりと天秤
ユーザー rutilicusrutilicus
提出日時 2020-08-31 23:17:38
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 430 ms / 5,000 ms
コード長 667 bytes
コンパイル時間 14,703 ms
コンパイル使用メモリ 443,136 KB
実行使用メモリ 73,072 KB
最終ジャッジ日時 2024-04-28 11:30:56
合計ジャッジ時間 22,696 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 301 ms
51,908 KB
testcase_01 AC 299 ms
51,480 KB
testcase_02 AC 308 ms
51,984 KB
testcase_03 AC 308 ms
51,872 KB
testcase_04 AC 327 ms
52,428 KB
testcase_05 AC 430 ms
70,380 KB
testcase_06 AC 294 ms
51,512 KB
testcase_07 AC 409 ms
71,440 KB
testcase_08 AC 304 ms
51,784 KB
testcase_09 AC 334 ms
52,440 KB
testcase_10 AC 424 ms
73,072 KB
testcase_11 AC 312 ms
51,804 KB
testcase_12 AC 308 ms
51,832 KB
testcase_13 AC 307 ms
51,592 KB
testcase_14 AC 306 ms
51,528 KB
testcase_15 AC 311 ms
51,532 KB
testcase_16 AC 313 ms
51,876 KB
testcase_17 AC 313 ms
51,792 KB
testcase_18 AC 411 ms
61,176 KB
testcase_19 AC 426 ms
69,216 KB
testcase_20 AC 422 ms
69,008 KB
testcase_21 AC 406 ms
68,096 KB
testcase_22 AC 417 ms
69,084 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