結果

問題 No.4 おもりと天秤
ユーザー hacchahaccha
提出日時 2023-07-02 20:34:57
言語 Ruby
(3.3.0)
結果
AC  
実行時間 148 ms / 5,000 ms
コード長 298 bytes
コンパイル時間 64 ms
コンパイル使用メモリ 11,508 KB
実行使用メモリ 15,324 KB
最終ジャッジ日時 2023-09-23 16:32:03
合計ジャッジ時間 4,003 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,116 KB
testcase_01 AC 81 ms
15,120 KB
testcase_02 AC 87 ms
15,116 KB
testcase_03 AC 84 ms
15,124 KB
testcase_04 AC 87 ms
15,272 KB
testcase_05 AC 145 ms
15,096 KB
testcase_06 AC 79 ms
15,072 KB
testcase_07 AC 144 ms
15,324 KB
testcase_08 AC 139 ms
15,240 KB
testcase_09 AC 137 ms
15,096 KB
testcase_10 AC 148 ms
15,040 KB
testcase_11 AC 82 ms
15,224 KB
testcase_12 AC 80 ms
15,324 KB
testcase_13 AC 80 ms
15,024 KB
testcase_14 AC 81 ms
15,068 KB
testcase_15 AC 80 ms
15,304 KB
testcase_16 AC 84 ms
15,144 KB
testcase_17 AC 80 ms
15,272 KB
testcase_18 AC 141 ms
15,144 KB
testcase_19 AC 144 ms
15,292 KB
testcase_20 AC 145 ms
15,128 KB
testcase_21 AC 143 ms
15,032 KB
testcase_22 AC 144 ms
15,016 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
weights = gets.split.map(&:to_i)

dp = Array.new(10001, false)
sum = 0
dp[0] = true
N.times do
  w = weights.shift
  sum += w

  10000.downto(0) do |i|
    if dp[i]
      dp[i + w] = true
    end
  end
end

if sum % 2 == 0 && dp[sum / 2]
  puts "possible"
else
  puts "impossible"
end
0