結果

問題 No.4 おもりと天秤
ユーザー wotsushiwotsushi
提出日時 2016-12-24 08:20:39
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 429 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 11,336 KB
実行使用メモリ 15,324 KB
最終ジャッジ日時 2023-08-21 07:49:27
合計ジャッジ時間 7,508 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,312 KB
testcase_01 AC 87 ms
15,160 KB
testcase_02 AC 112 ms
15,324 KB
testcase_03 AC 80 ms
15,032 KB
testcase_04 AC 80 ms
15,312 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
W = gets.split.map(&:to_i)
def f(i, w)
  @dp ||= {}
  @dp[[i, w]] ||= if i == 0
                    w == 0 || w == W[0]
                  elsif w < W[i]
                    f(i - 1, w)
                  else
                    f(i - 1, w) || f(i - 1, w - W[i])
                  end
end
s = W.inject(:+)
ans = if s % 2 == 0 and f(N - 1, s / 2)
        "possible"
      else
        "impossible"
      end
puts ans
0