結果

問題 No.4 おもりと天秤
ユーザー LaLa
提出日時 2020-11-23 17:39:16
言語 Ruby
(3.3.0)
結果
AC  
実行時間 203 ms / 5,000 ms
コード長 293 bytes
コンパイル時間 52 ms
コンパイル使用メモリ 11,220 KB
実行使用メモリ 15,340 KB
最終ジャッジ日時 2023-09-30 23:57:23
合計ジャッジ時間 4,400 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
15,020 KB
testcase_01 AC 81 ms
15,136 KB
testcase_02 AC 98 ms
15,104 KB
testcase_03 AC 94 ms
15,044 KB
testcase_04 AC 100 ms
15,132 KB
testcase_05 AC 203 ms
15,120 KB
testcase_06 AC 83 ms
15,232 KB
testcase_07 AC 200 ms
15,280 KB
testcase_08 AC 82 ms
15,004 KB
testcase_09 AC 196 ms
15,216 KB
testcase_10 AC 200 ms
15,096 KB
testcase_11 AC 88 ms
15,256 KB
testcase_12 AC 83 ms
15,328 KB
testcase_13 AC 87 ms
15,260 KB
testcase_14 AC 87 ms
15,028 KB
testcase_15 AC 84 ms
15,256 KB
testcase_16 AC 88 ms
15,156 KB
testcase_17 AC 88 ms
15,340 KB
testcase_18 AC 198 ms
15,312 KB
testcase_19 AC 197 ms
15,124 KB
testcase_20 AC 203 ms
15,028 KB
testcase_21 AC 201 ms
15,100 KB
testcase_22 AC 198 ms
15,332 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N=gets.to_i
W=gets.split.map(&:to_i)
S=W.sum

if S%2==1
    puts "impossible"
    exit
end

DP=Array.new(11000,0)
DP[0]=1

for i in 0...N do
    for j in 10500.downto(0) do
        DP[j]=1 if 0<=j-W[i] && DP[j-W[i]]==1
    end
end

puts "possible" if DP[S/2]==1
puts "impossible" if DP[S/2]!=1
0