結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-04-06 12:43:09 | 
| 言語 | Kotlin (2.1.0) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 783 bytes | 
| コンパイル時間 | 12,173 ms | 
| コンパイル使用メモリ | 439,424 KB | 
| 実行使用メモリ | 113,692 KB | 
| 最終ジャッジ日時 | 2024-11-20 17:47:57 | 
| 合計ジャッジ時間 | 24,992 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 22 TLE * 1 | 
ソースコード
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")
    }
}
            
            
            
        