結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-09-04 16:44:42 |
| 言語 | Crystal (1.14.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 532 bytes |
| コンパイル時間 | 12,200 ms |
| コンパイル使用メモリ | 309,580 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-09-04 16:44:57 |
| 合計ジャッジ時間 | 13,102 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 23 |
ソースコード
n = gets.not_nil!.to_i
w = Array(Int32).new(n) { gets.not_nil!.to_i }
t = w.sum
if t.odd?
puts "impossible"
exit
end
th = t // 2
# Create a 2D array with n+1 rows and th+1 columns, initialized to 0
m = Array(Array(Int32)).new(n + 1) { Array(Int32).new(th + 1, 0) }
(1...n).each do |i|
(0..th).each do |j|
if j < w[i]
m[i][j] = m[i - 1][j]
else
m[i][j] = Math.max(m[i - 1][j - w[i]] + w[i], m[i - 1][j])
end
if m[i][j] == th
puts "possible"
exit
end
end
end
puts "impossible"
vjudge1