結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-31 18:29:16 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 338 bytes |
| コンパイル時間 | 437 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 19,968 KB |
| 最終ジャッジ日時 | 2024-11-22 11:09:03 |
| 合計ジャッジ時間 | 3,388 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 13 |
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - n Syntax OK
ソースコード
n = gets.to_i
w = gets.split.map(&:to_i)
total = w.sum
if total % 2 == 1
puts "impossible"
exit 0
end
dp = [false] * (total / 2 + 1)
dp[0] = true
w.each do |wi|
(0..(dp.size-1)).to_a.reverse.each do |num|
dp[wi+num] = true if wi + num <= total / 2 && dp[wi]
end
end
puts dp[total/2] ? "possible" : "impossible"