結果
問題 | No.4 おもりと天秤 |
ユーザー |
|
提出日時 | 2019-12-03 09:28:14 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 741 bytes |
コンパイル時間 | 19,520 ms |
コンパイル使用メモリ | 383,676 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-26 08:17:33 |
合計ジャッジ時間 | 12,259 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
fn main() { // input let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); let n: usize = s.trim().parse().unwrap(); s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); let a: Vec<usize> = s .trim() .split_whitespace() .map(|e| e.parse().unwrap()) .collect(); // calc let mut dp: Vec<bool> = vec![false; 10010]; let total: usize = a.iter().sum(); dp[0] = true; for i in 0..n { for j in (a[i]..10001).rev() { dp[j] |= dp[j - a[i]]; if dp[j] && dp[total - j] && j * 2 == total { println!("possible"); return; } } } println!("impossible"); }