結果

問題 No.4 おもりと天秤
ユーザー komkomhkomkomh
提出日時 2019-04-06 12:37:14
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 663 bytes
コンパイル時間 9,725 ms
コンパイル使用メモリ 432,156 KB
実行使用メモリ 95,312 KB
最終ジャッジ日時 2024-04-30 20:09:58
合計ジャッジ時間 21,741 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 268 ms
60,428 KB
testcase_01 AC 262 ms
95,312 KB
testcase_02 AC 280 ms
57,400 KB
testcase_03 AC 283 ms
57,088 KB
testcase_04 AC 285 ms
57,040 KB
testcase_05 AC 284 ms
57,052 KB
testcase_06 AC 273 ms
56,996 KB
testcase_07 AC 272 ms
57,180 KB
testcase_08 AC 270 ms
57,032 KB
testcase_09 AC 279 ms
57,020 KB
testcase_10 AC 273 ms
57,032 KB
testcase_11 AC 270 ms
56,960 KB
testcase_12 AC 325 ms
56,948 KB
testcase_13 AC 275 ms
56,968 KB
testcase_14 AC 270 ms
56,976 KB
testcase_15 AC 279 ms
57,040 KB
testcase_16 AC 281 ms
57,004 KB
testcase_17 AC 270 ms
56,952 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