結果

問題 No.4 おもりと天秤
ユーザー komkomhkomkomh
提出日時 2019-04-06 12:35:01
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 564 bytes
コンパイル時間 12,144 ms
コンパイル使用メモリ 426,972 KB
実行使用メモリ 95,112 KB
最終ジャッジ日時 2024-04-30 20:09:10
合計ジャッジ時間 17,683 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 281 ms
60,516 KB
testcase_01 AC 261 ms
95,112 KB
testcase_02 AC 290 ms
57,232 KB
testcase_03 AC 290 ms
57,056 KB
testcase_04 AC 280 ms
57,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