結果

問題 No.4 おもりと天秤
コンテスト
ユーザー tonyu0
提出日時 2019-12-03 09:28:14
言語 Rust
(1.97.1 + proconio + num + itertools + ACL)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 1 ms / 5,000 ms
+ 461µs
コード長 741 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 459 ms
コンパイル使用メモリ 187,956 KB
実行使用メモリ 9,872 KB
最終ジャッジ日時 2026-09-30 06:27:15
合計ジャッジ時間 2,182 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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");
}
0