結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-11-12 14:11:40 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 5,000 ms | 
| コード長 | 518 bytes | 
| コンパイル時間 | 14,246 ms | 
| コンパイル使用メモリ | 378,868 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-12 14:11:56 | 
| 合計ジャッジ時間 | 16,049 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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");
    }
}
            
            
            
        