結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2023-04-06 01:11:00 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 657 bytes |
コンパイル時間 | 20,335 ms |
コンパイル使用メモリ | 401,072 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-02 03:54:35 |
合計ジャッジ時間 | 14,322 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
use std::io::{stdin, BufRead}; fn main() { let stdin = stdin(); let mut stdin = stdin.lock().lines().map(Result::unwrap); let _n = stdin.next().unwrap().parse::<usize>().unwrap(); let w = stdin .next() .unwrap() .split_whitespace() .map(|x| x.parse::<usize>().unwrap()) .collect::<Vec<_>>(); let lim = w.iter().sum::<usize>() + 1; let mut dp = vec![false; lim]; dp[0] = true; for &w in &w { for i in (0..lim - w).rev() { dp[i + w] |= dp[i]; } } let ans = lim % 2 == 1 && dp[lim / 2]; println!("{}", ["impossible", "possible"][ans as usize]); }