結果
| 問題 | No.4 おもりと天秤 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-12 14:11:40 |
| 言語 | Rust (1.94.0 + proconio + num + itertools) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 518 bytes |
| 記録 | |
| コンパイル時間 | 1,325 ms |
| コンパイル使用メモリ | 191,360 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-09 13:38:31 |
| 合計ジャッジ時間 | 2,784 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
use proconio::input;
fn main() {
input! {
n: usize,
w: [usize; n],
}
let sum = w.iter().sum::<usize>();
if sum % 2 == 1 {
println!("impossible");
return;
}
let mut dp = vec![0; sum + 1];
dp[0] = 1;
for i in 0..n {
let mut ndp = dp.clone();
for j in w[i]..=sum {
ndp[j] |= dp[j - w[i]];
}
dp = ndp;
}
if dp[sum/2] == 1 {
println!("possible");
}else {
println!("impossible");
}
}