結果

問題 No.4 おもりと天秤
ユーザー komkomhkomkomh
提出日時 2019-04-06 12:43:09
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 783 bytes
コンパイル時間 12,472 ms
コンパイル使用メモリ 419,700 KB
実行使用メモリ 85,992 KB
最終ジャッジ日時 2023-08-13 01:36:45
合計ジャッジ時間 25,018 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 292 ms
56,144 KB
testcase_01 AC 291 ms
85,992 KB
testcase_02 AC 302 ms
53,008 KB
testcase_03 AC 287 ms
52,836 KB
testcase_04 AC 285 ms
52,852 KB
testcase_05 AC 293 ms
52,888 KB
testcase_06 AC 285 ms
53,384 KB
testcase_07 AC 293 ms
52,928 KB
testcase_08 AC 289 ms
52,864 KB
testcase_09 AC 286 ms
52,912 KB
testcase_10 AC 286 ms
52,888 KB
testcase_11 AC 291 ms
52,956 KB
testcase_12 AC 288 ms
52,968 KB
testcase_13 AC 286 ms
52,804 KB
testcase_14 AC 287 ms
52,844 KB
testcase_15 AC 284 ms
52,924 KB
testcase_16 AC 285 ms
53,004 KB
testcase_17 AC 289 ms
52,868 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 {
            for (i in index + 1 until W.size) {
                if (search(i, currentSum)) {
                    return true
                }
            }
            return false
        }
    }

    when (search(0, 0)) {
        true -> println("possible")
        false -> println("impossible")
    }
}
0