結果
| 問題 | No.4 おもりと天秤 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-29 02:51:19 |
| 言語 | Rust (1.97.1 + proconio + num + itertools + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 2 ms / 5,000 ms |
| + 187µs | |
| コード長 | 819 bytes |
| 記録 | |
| コンパイル時間 | 616 ms |
| コンパイル使用メモリ | 179,292 KB |
| 実行使用メモリ | 6,528 KB |
| 最終ジャッジ日時 | 2026-09-19 10:50:34 |
| 合計ジャッジ時間 | 2,807 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
fn main() {
let mut n = String::new();
std::io::stdin().read_line(&mut n).ok();
let n: usize = n.trim().parse().unwrap();
let mut w = String::new();
std::io::stdin().read_line(&mut w).ok();
let w: Vec<usize> = w.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
let summary = w.iter().sum::<usize>();
if summary % 2 == 1 {
println!("impossible");
return;
}
let limit = summary/2;
let mut dp = vec![vec![false; limit+1]; n+1];
dp[0][0] = true;
for i in 0..n {
for j in 0..=limit {
dp[i+1][j] |= dp[i][j];
if j+w[i]<=limit {
dp[i+1][j+w[i]] |= dp[i][j];
}
}
}
if dp[n][limit] {
println!("possible");
} else {
println!("impossible");
}
}