結果

問題 No.4 おもりと天秤
ユーザー shi-moshi-mo
提出日時 2016-03-29 00:30:57
言語 Ruby
(3.2.2)
結果
AC  
実行時間 149 ms / 5,000 ms
コード長 254 bytes
コンパイル時間 495 ms
コンパイル使用メモリ 11,148 KB
実行使用メモリ 15,304 KB
最終ジャッジ日時 2023-09-08 16:37:30
合計ジャッジ時間 3,443 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
14,988 KB
testcase_01 AC 86 ms
15,188 KB
testcase_02 AC 89 ms
15,208 KB
testcase_03 AC 84 ms
14,988 KB
testcase_04 AC 85 ms
15,076 KB
testcase_05 AC 116 ms
15,228 KB
testcase_06 AC 85 ms
15,268 KB
testcase_07 AC 121 ms
15,184 KB
testcase_08 AC 84 ms
15,140 KB
testcase_09 AC 149 ms
15,000 KB
testcase_10 AC 123 ms
15,304 KB
testcase_11 AC 84 ms
15,192 KB
testcase_12 AC 84 ms
15,228 KB
testcase_13 AC 83 ms
15,176 KB
testcase_14 AC 83 ms
15,132 KB
testcase_15 AC 84 ms
15,132 KB
testcase_16 AC 83 ms
14,984 KB
testcase_17 AC 83 ms
15,096 KB
testcase_18 AC 128 ms
15,032 KB
testcase_19 AC 114 ms
15,224 KB
testcase_20 AC 113 ms
15,096 KB
testcase_21 AC 111 ms
15,268 KB
testcase_22 AC 113 ms
15,140 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
w = gets.chomp!.split.map(&:to_i)

s = w.inject(:+)
if s.odd?
  puts 'impossible'
  exit 0
end

dp = [ true ]
(n-1).times do |i|
  (dp.size - 1).downto(0) do |j|
    dp[j + w[i]] |= dp[j]
  end
end

puts dp[s/2] ? 'possible' : 'impossible'
0