結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 303 ms
60,460 KB
testcase_01 AC 304 ms
95,144 KB
testcase_02 AC 314 ms
57,012 KB
testcase_03 AC 303 ms
56,788 KB
testcase_04 AC 305 ms
56,884 KB
testcase_05 AC 315 ms
57,148 KB
testcase_06 AC 306 ms
56,944 KB
testcase_07 AC 310 ms
57,180 KB
testcase_08 AC 306 ms
56,904 KB
testcase_09 AC 313 ms
57,160 KB
testcase_10 AC 314 ms
57,112 KB
testcase_11 AC 307 ms
56,888 KB
testcase_12 AC 311 ms
56,984 KB
testcase_13 AC 304 ms
56,804 KB
testcase_14 AC 305 ms
56,944 KB
testcase_15 AC 304 ms
56,900 KB
testcase_16 AC 302 ms
56,960 KB
testcase_17 AC 303 ms
56,784 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