結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2017-02-11 12:08:46 |
言語 | Ruby (3.4.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 590 bytes |
コンパイル時間 | 143 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,288 KB |
最終ジャッジ日時 | 2024-12-29 12:08:56 |
合計ジャッジ時間 | 3,189 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 WA * 8 |
コンパイルメッセージ
Syntax OK
ソースコード
N = gets.to_i @w_list = gets.chomp.split.map(&:to_i) @half = 0 @dp = Array.new(100, Array.new(10001, true)) def solve(idx, total) return false if idx >= N || total > @half return @dp[idx][total] if @dp[idx][total] == false new_total = total + @w_list[idx] return true if new_total == @half return true if solve(idx + 1, total) || solve(idx + 1, new_total) return @dp[idx][total] = false end def main total = @w_list.inject(:+) return "impossible" if total & 1 == 1 @half = total >> 1 @w_list.sort! return solve(0, 0) ? "possible" : "impossible" end puts main()