結果
| 問題 | No.4 おもりと天秤 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-06 12:37:14 |
| 言語 | Kotlin (2.3.20) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 663 bytes |
| 記録 | |
| コンパイル時間 | 8,526 ms |
| コンパイル使用メモリ | 465,344 KB |
| 実行使用メモリ | 90,608 KB |
| 最終ジャッジ日時 | 2026-05-14 21:09:22 |
| 合計ジャッジ時間 | 19,268 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 TLE * 1 -- * 4 |
ソースコード
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")
}
}