結果

問題 No.4 おもりと天秤
ユーザー LaLa
提出日時 2020-11-23 16:55:05
言語 Ruby
(3.2.2)
結果
WA  
実行時間 -
コード長 316 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 11,400 KB
実行使用メモリ 15,356 KB
最終ジャッジ日時 2023-09-30 23:55:40
合計ジャッジ時間 3,399 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
15,044 KB
testcase_01 AC 80 ms
15,264 KB
testcase_02 AC 74 ms
15,152 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 79 ms
15,156 KB
testcase_07 WA -
testcase_08 AC 79 ms
15,172 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 79 ms
15,120 KB
testcase_12 AC 81 ms
15,044 KB
testcase_13 AC 81 ms
15,308 KB
testcase_14 AC 81 ms
15,352 KB
testcase_15 AC 80 ms
15,148 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 77 ms
15,164 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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(N+1,0))
DP[0][0]=1

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

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