結果

問題 No.4 おもりと天秤
ユーザー hacchahaccha
提出日時 2023-07-02 20:36:27
言語 Ruby
(3.3.0)
結果
AC  
実行時間 150 ms / 5,000 ms
コード長 315 bytes
コンパイル時間 113 ms
コンパイル使用メモリ 11,248 KB
実行使用メモリ 15,344 KB
最終ジャッジ日時 2023-09-23 16:33:38
合計ジャッジ時間 3,572 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,040 KB
testcase_01 AC 81 ms
15,316 KB
testcase_02 AC 79 ms
15,344 KB
testcase_03 AC 78 ms
15,156 KB
testcase_04 AC 79 ms
15,040 KB
testcase_05 AC 150 ms
15,108 KB
testcase_06 AC 77 ms
15,256 KB
testcase_07 AC 145 ms
15,072 KB
testcase_08 AC 139 ms
15,056 KB
testcase_09 AC 141 ms
15,076 KB
testcase_10 AC 146 ms
15,280 KB
testcase_11 AC 78 ms
15,056 KB
testcase_12 AC 77 ms
15,148 KB
testcase_13 AC 77 ms
15,100 KB
testcase_14 AC 80 ms
15,044 KB
testcase_15 AC 79 ms
15,124 KB
testcase_16 AC 77 ms
15,176 KB
testcase_17 AC 78 ms
15,032 KB
testcase_18 AC 146 ms
15,132 KB
testcase_19 AC 145 ms
15,052 KB
testcase_20 AC 147 ms
15,128 KB
testcase_21 AC 147 ms
15,132 KB
testcase_22 AC 149 ms
15,128 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

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

  size.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