結果

問題 No.4 おもりと天秤
ユーザー LaLa
提出日時 2020-11-23 17:00:48
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 362 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 11,488 KB
実行使用メモリ 15,348 KB
最終ジャッジ日時 2023-09-30 23:55:53
合計ジャッジ時間 4,852 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,184 KB
testcase_01 AC 75 ms
15,032 KB
testcase_02 AC 102 ms
15,068 KB
testcase_03 AC 96 ms
15,104 KB
testcase_04 AC 112 ms
15,200 KB
testcase_05 AC 306 ms
15,216 KB
testcase_06 AC 79 ms
15,212 KB
testcase_07 AC 296 ms
15,204 KB
testcase_08 AC 75 ms
15,196 KB
testcase_09 AC 218 ms
15,108 KB
testcase_10 AC 297 ms
15,252 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 79 ms
15,192 KB
testcase_14 WA -
testcase_15 AC 83 ms
15,168 KB
testcase_16 AC 96 ms
15,224 KB
testcase_17 AC 93 ms
15,068 KB
testcase_18 AC 263 ms
15,008 KB
testcase_19 AC 296 ms
15,072 KB
testcase_20 AC 298 ms
15,112 KB
testcase_21 AC 302 ms
15,172 KB
testcase_22 AC 296 ms
15,144 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

S/=2
DP=Array.new(N+1,Array.new(10001,0))
DP[0][0]=1

for i in 1..N do
    for j in 0..10000 do
        DP[i][j+W[i-1]]=1 if j+W[i-1]<=10000 && DP[i-1][j]==1
        DP[i][j]=1 if DP[i-1][j]==1
    end
end

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