結果

問題 No.4 おもりと天秤
ユーザー taba
提出日時 2024-07-30 12:01:10
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 759 bytes
コンパイル時間 12,336 ms
コンパイル使用メモリ 402,936 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-30 12:01:24
合計ジャッジ時間 13,284 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused imports: `HashMap`, `HashSet`
 --> src/main.rs:1:24
  |
1 | use std::collections::{HashMap, HashSet};
  |                        ^^^^^^^  ^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: `proconio::marker::Chars`
 --> src/main.rs:3:5
  |
3 | use proconio::marker::Chars;
  |     ^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #

use std::collections::{HashMap, HashSet};

use proconio::marker::Chars;

fn main() {
    proconio::input! {
        n: u64,
        w: [u64; n],
    }
    let sum = w.iter().sum::<u64>();
    if sum % 2 == 1 {
        println!("impossible");
        return;
    }
    let half = sum / 2;
    let mut memo = vec![false; half as usize + 1];
    memo[0] = true;
    for w in w {
        for i in (0..half + 1).rev() {
            if memo[i as usize] == false || i + w > half {
                continue;
            }
            memo[(i + w) as usize] = true;
        }
    }
    if memo[half as usize] {
        println!("possible");
    } else {
        println!("impossible");
    }
}

#[cfg(test)]
mod test {
    use super::*;
    #[test]
    fn test() {}
}
0