結果

問題 No.4 おもりと天秤
ユーザー くわいくわい
提出日時 2015-11-05 21:46:01
言語 Scala(Beta)
(3.4.0)
結果
WA  
実行時間 -
コード長 649 bytes
コンパイル時間 9,398 ms
コンパイル使用メモリ 256,816 KB
実行使用メモリ 64,332 KB
最終ジャッジ日時 2023-09-11 14:54:54
合計ジャッジ時間 33,877 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 983 ms
63,188 KB
testcase_01 AC 952 ms
62,800 KB
testcase_02 AC 995 ms
63,428 KB
testcase_03 AC 990 ms
63,588 KB
testcase_04 AC 987 ms
63,436 KB
testcase_05 AC 1,033 ms
63,588 KB
testcase_06 AC 984 ms
63,272 KB
testcase_07 AC 1,022 ms
63,464 KB
testcase_08 AC 965 ms
62,860 KB
testcase_09 AC 1,029 ms
63,588 KB
testcase_10 AC 1,019 ms
63,448 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 993 ms
63,352 KB
testcase_14 WA -
testcase_15 AC 988 ms
63,704 KB
testcase_16 AC 999 ms
63,272 KB
testcase_17 AC 1,003 ms
63,180 KB
testcase_18 AC 1,017 ms
63,276 KB
testcase_19 AC 1,032 ms
63,440 KB
testcase_20 AC 1,025 ms
64,332 KB
testcase_21 AC 1,008 ms
63,588 KB
testcase_22 AC 1,022 ms
63,372 KB
権限があれば一括ダウンロードができます

ソースコード

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