結果

問題 No.4 おもりと天秤
ユーザー komkomhkomkomh
提出日時 2019-04-06 12:37:14
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 663 bytes
コンパイル時間 12,692 ms
コンパイル使用メモリ 421,364 KB
実行使用メモリ 85,980 KB
最終ジャッジ日時 2023-08-13 01:36:10
合計ジャッジ時間 25,530 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 292 ms
56,208 KB
testcase_01 AC 286 ms
85,980 KB
testcase_02 AC 312 ms
57,304 KB
testcase_03 AC 295 ms
52,964 KB
testcase_04 AC 292 ms
52,960 KB
testcase_05 AC 318 ms
52,856 KB
testcase_06 AC 287 ms
52,828 KB
testcase_07 AC 309 ms
53,000 KB
testcase_08 AC 291 ms
53,220 KB
testcase_09 AC 305 ms
53,004 KB
testcase_10 AC 308 ms
52,852 KB
testcase_11 AC 304 ms
53,028 KB
testcase_12 AC 303 ms
52,944 KB
testcase_13 AC 310 ms
52,944 KB
testcase_14 AC 305 ms
52,944 KB
testcase_15 AC 302 ms
52,808 KB
testcase_16 AC 297 ms
52,932 KB
testcase_17 AC 296 ms
53,044 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder

fun main() {
    readLine()!!.toInt()
    val W: List<Int> = readLine()!!.split(" ").map(String::toInt)

    val sum: Int = W.sum()
    if (sum % 2 != 0) {
        println("impossible")
        return
    }

    val halfW = sum / 2

    fun search(index: Int, sum: Int): Boolean {
        val currentSum = sum + W[index]
        return if (currentSum > halfW) {
            false
        } else if (currentSum == halfW) {
            true
        } else {
            (index + 1 until W.size).any { search(it, currentSum) }
        }
    }

    if (search(0, 0)) {
        println("possible")
    } else {
        println("impossible")
    }
}
0