結果

問題 No.4 おもりと天秤
ユーザー くわい
提出日時 2015-11-05 21:46:01
言語 Scala(Beta)
(3.6.2)
結果
WA  
実行時間 -
コード長 649 bytes
コンパイル時間 9,119 ms
コンパイル使用メモリ 265,540 KB
実行使用メモリ 65,812 KB
最終ジャッジ日時 2024-06-29 05:04:59
合計ジャッジ時間 28,882 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner

object Problem004 {

  def proc(n: Int, weight: Seq[Int]): String = {
    if (weight.sum % 2 != 0) {
      return "impossible"
    }

    val target = weight.sum / 2
    val dp = Array.fill(target + 1)(false)
    dp(0) = true

    for (w <- weight) {
      for (d <- 0 until target) {
        if (dp(d) && d + w <= target) dp(d + w) = true
      }
    }

    if (dp(target)) "possible" else "impossible"
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val weight = Seq.fill(n)(sc.nextInt())

    val result: String = proc(n, weight)
    println(result)
  }
}
0