結果

問題 No.4 おもりと天秤
ユーザー nakamura sosukenakamura sosuke
提出日時 2019-07-18 18:45:06
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 312 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 11,412 KB
実行使用メモリ 24,172 KB
最終ジャッジ日時 2023-08-26 20:31:07
合計ジャッジ時間 3,767 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,308 KB
testcase_01 AC 83 ms
15,240 KB
testcase_02 AC 75 ms
15,184 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 124 ms
22,964 KB
testcase_06 AC 83 ms
15,192 KB
testcase_07 AC 121 ms
22,812 KB
testcase_08 AC 83 ms
15,136 KB
testcase_09 WA -
testcase_10 AC 128 ms
24,172 KB
testcase_11 AC 83 ms
15,040 KB
testcase_12 WA -
testcase_13 AC 84 ms
15,292 KB
testcase_14 AC 83 ms
15,172 KB
testcase_15 AC 84 ms
15,264 KB
testcase_16 AC 81 ms
15,084 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 118 ms
21,580 KB
testcase_20 AC 111 ms
21,276 KB
testcase_21 AC 113 ms
20,740 KB
testcase_22 AC 113 ms
20,980 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
W = gets.split.map(&:to_i).sort!

def f(n, ws)
  sum = 0; ws.each{ |w| sum += w }
  return false if sum.odd?

  dp = {}
  dp[0] = true

  ws.each do | w |
    dpc = dp.clone
    dpc.each do | k, v |
      dp[k+w] = dp[k]
    end
  end

  return dp[n/2]
end

puts f(N, W) ? 'possible' : 'impossible'
0