結果

問題 No.4 おもりと天秤
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-01-28 18:29:06
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 327 bytes
コンパイル時間 43 ms
コンパイル使用メモリ 11,240 KB
実行使用メモリ 23,196 KB
最終ジャッジ日時 2023-10-13 20:49:33
合計ジャッジ時間 3,908 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,216 KB
testcase_01 AC 82 ms
15,084 KB
testcase_02 AC 82 ms
15,248 KB
testcase_03 WA -
testcase_04 AC 81 ms
15,016 KB
testcase_05 AC 167 ms
19,344 KB
testcase_06 AC 78 ms
15,188 KB
testcase_07 AC 163 ms
19,356 KB
testcase_08 AC 82 ms
15,228 KB
testcase_09 AC 218 ms
23,196 KB
testcase_10 AC 173 ms
19,816 KB
testcase_11 AC 79 ms
15,192 KB
testcase_12 AC 78 ms
15,264 KB
testcase_13 AC 79 ms
15,040 KB
testcase_14 AC 79 ms
15,080 KB
testcase_15 AC 79 ms
15,028 KB
testcase_16 WA -
testcase_17 AC 82 ms
15,228 KB
testcase_18 AC 157 ms
19,036 KB
testcase_19 AC 154 ms
18,800 KB
testcase_20 AC 152 ms
18,784 KB
testcase_21 AC 149 ms
18,692 KB
testcase_22 AC 155 ms
18,708 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.chomp.to_i
w = gets.chomp.split.map(&:to_i)
sum = w.sum
dp = Array.new(n) { Array.new(sum + 1) { false } }
dp[0][w[0]] = true
1.upto(n-1) do |i|
  wi = w[i]
  sum.times do |j|
    next unless dp[i-1][j]

    dp[i][j - wi] = true if j >= wi
    dp[i][j + wi] = true
  end
end
puts dp[n-1][0] ? 'possible' : 'impossible'
0