結果
問題 |
No.1017 Reiwa Sequence
|
ユーザー |
![]() |
提出日時 | 2020-04-04 10:39:22 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
(最新)
J_TLE
(最初)
|
実行時間 | - |
コード長 | 2,201 bytes |
コンパイル時間 | 11,512 ms |
コンパイル使用メモリ | 405,592 KB |
実行使用メモリ | 107,360 KB |
最終ジャッジ日時 | 2024-07-03 07:03:47 |
合計ジャッジ時間 | 54,017 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 2 |
other | AC * 12 WA * 38 |
ソースコード
#![allow(unused_imports)] #![allow(non_snake_case)] use std::cmp::*; use std::collections::*; use std::io::Write; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn get_idx(x: i64) -> usize { (x + 11 * 150000) as usize } fn main() { let n = read::<usize>(); let a = read_vec::<i64>(); let a = a.into_iter().take(22).collect::<Vec<_>>(); let mut dp = vec![None; 2 * 11 * 150000 + 1]; for i in 0..a.len() { for prev in -11 * 150000..11 * 150000 + 1 { if dp[get_idx(prev)] == None { continue; } let cand = prev + a[i]; if cand < 11 * 150000 && dp[get_idx(cand)] == None { dp[get_idx(cand)] = Some((Some(prev), i, 1)); } let cand = prev - a[i]; if cand > (-11 * 150000) && dp[get_idx(cand)] == None { dp[get_idx(cand)] = Some((Some(prev), i, -1)); } } if dp[get_idx(a[i])] == None { dp[get_idx(a[i])] = Some((None, i, 1)); } if dp[get_idx(-a[i])] == None { dp[get_idx(-a[i])] = Some((None, i, -1)); } } if dp[get_idx(0)] == None { println!("No"); } else { println!("Yes"); let mut answers = vec![0i64; n]; let mut cur = 0; loop { let (prev, i, sign) = dp[get_idx(cur)].unwrap(); answers[i] = a[i] * sign; if let Some(p) = prev { cur = p; } else { break; } } for i in 0..n - 1 { print!("{} ", answers[i]); } println!("{}", answers[n - 1]); } } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }