結果

問題 No.4 おもりと天秤
ユーザー LaLa
提出日時 2020-11-23 16:56:08
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 322 bytes
コンパイル時間 57 ms
コンパイル使用メモリ 11,492 KB
実行使用メモリ 15,352 KB
最終ジャッジ日時 2023-09-30 23:55:45
合計ジャッジ時間 4,880 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,200 KB
testcase_01 AC 81 ms
15,148 KB
testcase_02 AC 81 ms
15,284 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 253 ms
15,248 KB
testcase_06 AC 81 ms
15,216 KB
testcase_07 AC 253 ms
15,148 KB
testcase_08 AC 81 ms
15,192 KB
testcase_09 AC 203 ms
15,076 KB
testcase_10 AC 275 ms
15,148 KB
testcase_11 AC 82 ms
15,084 KB
testcase_12 AC 80 ms
15,172 KB
testcase_13 AC 88 ms
15,128 KB
testcase_14 AC 81 ms
15,276 KB
testcase_15 AC 81 ms
15,008 KB
testcase_16 WA -
testcase_17 AC 81 ms
15,164 KB
testcase_18 AC 242 ms
15,236 KB
testcase_19 AC 252 ms
15,144 KB
testcase_20 AC 256 ms
15,244 KB
testcase_21 AC 257 ms
15,056 KB
testcase_22 AC 254 ms
15,112 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(N*N+1,0))
DP[0][0]=1

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

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