結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  rutilicus | 
| 提出日時 | 2020-08-31 23:17:38 | 
| 言語 | Kotlin (2.1.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 407 ms / 5,000 ms | 
| コード長 | 667 bytes | 
| コンパイル時間 | 14,075 ms | 
| コンパイル使用メモリ | 440,568 KB | 
| 実行使用メモリ | 72,700 KB | 
| 最終ジャッジ日時 | 2024-11-17 02:47:42 | 
| 合計ジャッジ時間 | 23,276 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
コンパイルメッセージ
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")
            ^
            
            ソースコード
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()!!
}
            
            
            
        