結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,236 KB
testcase_01 AC 86 ms
15,248 KB
testcase_02 AC 83 ms
15,276 KB
testcase_03 WA -
testcase_04 AC 82 ms
15,212 KB
testcase_05 AC 169 ms
19,392 KB
testcase_06 AC 79 ms
15,280 KB
testcase_07 AC 167 ms
19,236 KB
testcase_08 AC 84 ms
15,124 KB
testcase_09 AC 213 ms
22,996 KB
testcase_10 AC 172 ms
19,824 KB
testcase_11 AC 79 ms
15,120 KB
testcase_12 AC 79 ms
15,308 KB
testcase_13 AC 78 ms
15,224 KB
testcase_14 AC 79 ms
15,280 KB
testcase_15 AC 80 ms
14,976 KB
testcase_16 WA -
testcase_17 AC 81 ms
15,028 KB
testcase_18 AC 159 ms
18,988 KB
testcase_19 AC 156 ms
18,916 KB
testcase_20 AC 156 ms
18,868 KB
testcase_21 AC 151 ms
18,540 KB
testcase_22 AC 151 ms
18,884 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+1).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