結果

問題 No.4 おもりと天秤
ユーザー DialBirdDialBird
提出日時 2016-11-13 09:20:41
言語 Ruby
(3.2.2)
結果
AC  
実行時間 148 ms / 5,000 ms
コード長 408 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 11,200 KB
実行使用メモリ 15,380 KB
最終ジャッジ日時 2023-09-08 17:14:02
合計ジャッジ時間 4,227 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,244 KB
testcase_01 AC 80 ms
15,156 KB
testcase_02 AC 88 ms
15,288 KB
testcase_03 AC 85 ms
15,160 KB
testcase_04 AC 88 ms
15,244 KB
testcase_05 AC 148 ms
15,120 KB
testcase_06 AC 82 ms
15,116 KB
testcase_07 AC 146 ms
15,300 KB
testcase_08 AC 80 ms
15,256 KB
testcase_09 AC 139 ms
15,380 KB
testcase_10 AC 147 ms
15,164 KB
testcase_11 AC 83 ms
15,044 KB
testcase_12 AC 83 ms
15,032 KB
testcase_13 AC 80 ms
15,156 KB
testcase_14 AC 82 ms
15,296 KB
testcase_15 AC 81 ms
15,268 KB
testcase_16 AC 85 ms
15,128 KB
testcase_17 AC 83 ms
15,028 KB
testcase_18 AC 145 ms
15,172 KB
testcase_19 AC 145 ms
15,184 KB
testcase_20 AC 148 ms
15,120 KB
testcase_21 AC 148 ms
15,176 KB
testcase_22 AC 147 ms
15,292 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:5: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

MAX_N = 100
MAX_W = 100

def main
  n = gets.to_i
  w_list = gets.split.map(&:to_i)
  w_sum = w_list.inject(:+)
  return "impossible" if w_sum % 2 == 1

  dp = [false] * (MAX_N * MAX_W + 1)
  dp[0] = true

  w_list.each do |w|
    (MAX_N * MAX_W - w).downto(0) do |i|
      dp[i+w] = true if dp[i]
    end
  end

  if dp[w_sum/2] 
    return "possible" 
  else 
    return "impossible"
  end
end

puts main()
0