結果
問題 | No.1017 Reiwa Sequence |
ユーザー | fukafukatani |
提出日時 | 2020-04-04 10:49:18 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 482 ms / 2,000 ms |
コード長 | 2,325 bytes |
コンパイル時間 | 11,397 ms |
コンパイル使用メモリ | 402,084 KB |
実行使用メモリ | 213,552 KB |
最終ジャッジ日時 | 2024-07-03 07:05:14 |
合計ジャッジ時間 | 55,208 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 70 ms
104,968 KB |
testcase_01 | AC | 53 ms
104,988 KB |
testcase_02 | AC | 44 ms
104,932 KB |
testcase_03 | AC | 104 ms
105,028 KB |
testcase_04 | AC | 45 ms
105,008 KB |
testcase_05 | AC | 63 ms
105,016 KB |
testcase_06 | AC | 54 ms
104,968 KB |
testcase_07 | AC | 46 ms
104,848 KB |
testcase_08 | AC | 45 ms
105,024 KB |
testcase_09 | AC | 154 ms
116,764 KB |
testcase_10 | AC | 302 ms
126,616 KB |
testcase_11 | AC | 134 ms
110,296 KB |
testcase_12 | AC | 380 ms
138,452 KB |
testcase_13 | AC | 401 ms
138,580 KB |
testcase_14 | AC | 134 ms
109,908 KB |
testcase_15 | AC | 154 ms
117,076 KB |
testcase_16 | AC | 134 ms
110,292 KB |
testcase_17 | AC | 231 ms
138,324 KB |
testcase_18 | AC | 136 ms
110,292 KB |
testcase_19 | AC | 385 ms
150,492 KB |
testcase_20 | AC | 376 ms
142,940 KB |
testcase_21 | AC | 382 ms
143,964 KB |
testcase_22 | AC | 391 ms
143,064 KB |
testcase_23 | AC | 381 ms
153,304 KB |
testcase_24 | AC | 355 ms
199,256 KB |
testcase_25 | AC | 347 ms
144,092 KB |
testcase_26 | AC | 327 ms
171,060 KB |
testcase_27 | AC | 392 ms
182,364 KB |
testcase_28 | AC | 357 ms
164,572 KB |
testcase_29 | AC | 376 ms
145,240 KB |
testcase_30 | AC | 379 ms
142,808 KB |
testcase_31 | AC | 369 ms
133,976 KB |
testcase_32 | AC | 313 ms
122,332 KB |
testcase_33 | AC | 273 ms
136,148 KB |
testcase_34 | AC | 347 ms
155,352 KB |
testcase_35 | AC | 320 ms
159,060 KB |
testcase_36 | AC | 377 ms
139,992 KB |
testcase_37 | AC | 315 ms
151,004 KB |
testcase_38 | AC | 323 ms
159,576 KB |
testcase_39 | AC | 345 ms
165,084 KB |
testcase_40 | AC | 436 ms
213,552 KB |
testcase_41 | AC | 437 ms
140,336 KB |
testcase_42 | AC | 482 ms
143,380 KB |
testcase_43 | AC | 440 ms
159,016 KB |
testcase_44 | AC | 225 ms
106,084 KB |
testcase_45 | AC | 443 ms
142,760 KB |
testcase_46 | AC | 434 ms
145,812 KB |
testcase_47 | AC | 386 ms
149,524 KB |
testcase_48 | AC | 367 ms
126,956 KB |
testcase_49 | AC | 232 ms
106,784 KB |
testcase_50 | AC | 235 ms
107,276 KB |
testcase_51 | AC | 35 ms
104,948 KB |
testcase_52 | AC | 311 ms
164,316 KB |
testcase_53 | AC | 291 ms
167,772 KB |
ソースコード
#![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() { let mut added = vec![]; 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 { added.push((get_idx(cand), Some(prev), 1)); } let cand = prev - a[i]; if cand > (-11 * 150000) && dp[get_idx(cand)] == None { added.push((get_idx(cand), Some(prev), -1)); } } for (idx, prev, sign) in added { dp[idx] = Some((prev, i, sign)); } 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() }