結果

問題 No.4 おもりと天秤
ユーザー DialBirdDialBird
提出日時 2017-02-11 13:09:45
言語 Ruby
(3.3.0)
結果
AC  
実行時間 150 ms / 5,000 ms
コード長 381 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 11,172 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2023-09-08 17:19:17
合計ジャッジ時間 3,559 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,044 KB
testcase_01 AC 79 ms
15,168 KB
testcase_02 AC 88 ms
15,160 KB
testcase_03 AC 83 ms
15,008 KB
testcase_04 AC 85 ms
15,232 KB
testcase_05 AC 147 ms
15,096 KB
testcase_06 AC 76 ms
15,224 KB
testcase_07 AC 150 ms
15,360 KB
testcase_08 AC 78 ms
15,224 KB
testcase_09 AC 142 ms
15,176 KB
testcase_10 AC 148 ms
15,052 KB
testcase_11 AC 81 ms
15,104 KB
testcase_12 AC 76 ms
15,340 KB
testcase_13 AC 79 ms
15,220 KB
testcase_14 AC 79 ms
15,076 KB
testcase_15 AC 80 ms
15,140 KB
testcase_16 AC 82 ms
15,092 KB
testcase_17 AC 81 ms
15,272 KB
testcase_18 AC 142 ms
15,100 KB
testcase_19 AC 144 ms
15,020 KB
testcase_20 AC 146 ms
15,216 KB
testcase_21 AC 143 ms
15,328 KB
testcase_22 AC 146 ms
15,260 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
@w_list = gets.chomp.split.map(&:to_i)
@half = 0
@dp = Array.new(10001, false)

def main
  total = @w_list.inject(:+)

  return "impossible" if total & 1 == 1

  @half = total >> 1
  @dp[0] = true

  @w_list.each do |w|
    (@dp.size - 1).downto(0) do |i|
      @dp[i+w] = true if @dp[i]
    end
  end

  return @dp[@half] ? "possible" : "impossible"
end

puts main()
0