結果

問題 No.4 おもりと天秤
ユーザー komkomhkomkomh
提出日時 2019-04-06 12:35:01
言語 Kotlin
(1.9.10)
結果
TLE  
実行時間 -
コード長 564 bytes
コンパイル時間 13,392 ms
コンパイル使用メモリ 417,388 KB
実行使用メモリ 93,924 KB
最終ジャッジ日時 2023-08-13 01:35:10
合計ジャッジ時間 22,695 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 306 ms
93,924 KB
testcase_01 AC 293 ms
52,996 KB
testcase_02 AC 325 ms
52,980 KB
testcase_03 AC 303 ms
53,020 KB
testcase_04 AC 313 ms
53,092 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
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) true
        else (index + 1 until W.size).any { search(it, currentSum) }
    }

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