結果

問題 No.4 おもりと天秤
ユーザー wotsushiwotsushi
提出日時 2016-12-24 08:34:27
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 298 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 11,372 KB
実行使用メモリ 42,148 KB
最終ジャッジ日時 2023-08-21 07:49:35
合計ジャッジ時間 3,805 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
15,076 KB
testcase_01 AC 80 ms
15,296 KB
testcase_02 AC 82 ms
15,152 KB
testcase_03 AC 81 ms
15,148 KB
testcase_04 AC 81 ms
15,288 KB
testcase_05 AC 157 ms
28,264 KB
testcase_06 AC 80 ms
15,152 KB
testcase_07 AC 157 ms
28,324 KB
testcase_08 AC 82 ms
15,288 KB
testcase_09 AC 267 ms
42,148 KB
testcase_10 AC 172 ms
30,248 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 79 ms
15,240 KB
testcase_14 WA -
testcase_15 AC 81 ms
15,284 KB
testcase_16 AC 82 ms
15,084 KB
testcase_17 AC 81 ms
15,320 KB
testcase_18 AC 161 ms
27,672 KB
testcase_19 AC 156 ms
27,028 KB
testcase_20 AC 155 ms
27,128 KB
testcase_21 AC 152 ms
26,360 KB
testcase_22 AC 154 ms
26,708 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
W = gets.split.map(&:to_i)
s = W.inject(:+)
dp = Array.new(s / 2 + 1, false)
dp[0] = true
W.product([*0..(s / 2 + 1)]).each do |w, i|
  if i >= w
    dp[i] ||= dp[i - w]
  end
end
ans = if s % 2 == 0 and dp[s / 2]
        "possible"
      else
        "impossible"
      end
puts ans
0