結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  cra77756176 | 
| 提出日時 | 2022-11-18 02:55:41 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 955 bytes | 
| コンパイル時間 | 14,804 ms | 
| コンパイル使用メモリ | 384,140 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-19 13:10:20 | 
| 合計ジャッジ時間 | 14,368 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
use std::io::{self, BufRead};
fn main() {
    let input = io::stdin()
        .lock()
        .lines()
        .map(|l| {
            l.unwrap()
                .split(' ')
                .map(|n| n.parse::<usize>().unwrap())
                .collect::<Vec<_>>()
        })
        .collect::<Vec<_>>();
    let sum = input[1].iter().sum::<usize>();
    if sum % 2 == 1 {
        println!("impossible");
    } else {
        let n = input[1].len();
        let goal = sum / 2;
        let mut possible = vec![vec![false; goal + 1]; n + 1];
        possible[0][0] = true;
        for i in 1..=n {
            for total in 0..=goal {
                possible[i][total] |= possible[i - 1][total];
                if input[1][i - 1] <= total {
                    possible[i][total] |= possible[i - 1][total - input[1][i - 1]];
                }
            }
        }
        println!("{}possible", if possible[n][goal] { "" } else { "im" });
    }
}
            
            
            
        