結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2016-06-12 22:38:11 |
言語 | Ruby (3.4.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 431 bytes |
コンパイル時間 | 285 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 19,748 KB |
最終ジャッジ日時 | 2024-10-09 13:06:31 |
合計ジャッジ時間 | 7,550 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 TLE * 1 -- * 17 |
コンパイルメッセージ
Main.rb:4: warning: assigned but unused variable - n Syntax OK
ソースコード
require 'pp' def main n = gets.to_i ws = gets.strip.split(' ').map{|e| e.to_i} sum = ws.reduce(:+) result = solve(ws, 0, sum) puts result ? "possible" : "impossible" end def solve(ws, acc, sum) if (sum % 2 === 1) return false end if (acc * 2 === sum) return true end if (ws.empty?) return false end nex = ws[0] _ws = ws[1..-1] solve(_ws, acc + nex, sum) || solve(_ws, acc, sum) end main()