結果

問題 No.4 おもりと天秤
コンテスト
ユーザー くわい
提出日時 2015-11-05 21:52:49
言語 Scala(Beta)
(3.8.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 635 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 15,805 ms
コンパイル使用メモリ 265,468 KB
実行使用メモリ 226,852 KB
最終ジャッジ日時 2026-01-30 15:33:18
合計ジャッジ時間 28,954 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other TLE * 1 -- * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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 <- target - w to 0 by -1 if dp(d)) {
        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