結果
問題 | No.1017 Reiwa Sequence |
ユーザー | fukafukatani |
提出日時 | 2020-04-03 23:06:12 |
言語 | Rust (1.77.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,865 bytes |
コンパイル時間 | 14,635 ms |
コンパイル使用メモリ | 379,348 KB |
実行使用メモリ | 299,476 KB |
最終ジャッジ日時 | 2024-07-03 05:40:30 |
合計ジャッジ時間 | 24,659 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
10,752 KB |
testcase_01 | AC | 3 ms
5,376 KB |
testcase_02 | AC | 3 ms
5,504 KB |
testcase_03 | AC | 4 ms
6,144 KB |
testcase_04 | AC | 4 ms
5,504 KB |
testcase_05 | AC | 4 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,504 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 82 ms
41,428 KB |
testcase_10 | AC | 1,323 ms
294,208 KB |
testcase_11 | AC | 40 ms
23,392 KB |
testcase_12 | TLE | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
コンパイルメッセージ
warning: variable does not need to be mutable --> src/main.rs:44:9 | 44 | let mut max_search = 30; | ----^^^^^^^^^^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default
ソースコード
#![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 yes(a: &Vec<i64>) { println!("Yes"); for &num in a.iter().take(a.len() - 1) { print!("{} ", num); } println!("{}", a[a.len() - 1]); } fn main() { let n = read::<usize>(); let a = read_vec::<usize>(); let mut poses = vec![vec![]; 150001]; for (i, &num) in a.iter().enumerate() { poses[num].push(i); } for i in 0..150001 { if poses[i].len() >= 2 { let mut answers = vec![0; n]; answers[poses[i][0]] = i as i64; answers[poses[i][1]] = -(i as i64); yes(&answers); return; } } let mut max_search = 30; let mut cand_pos = vec![]; let mut cand_num = vec![]; for i in 0..150001 { if poses[i].len() == 1 { cand_num.push(i as i64); cand_pos.push(poses[i][0]); } if cand_num.len() == max_search { break; } } let mut dp = HashSet::new(); let mut from = HashMap::new(); for i in 0..cand_num.len() { let clone = dp.clone(); for num in clone { if !dp.contains(&(cand_num[i] + num)) { from.insert(cand_num[i] + num, (Some(num), i, 1)); dp.insert(cand_num[i] + num); } if !dp.contains(&(-cand_num[i] + num)) { from.insert(-cand_num[i] + num, (Some(num), i, -1)); dp.insert(-cand_num[i] + num); } } if !dp.contains(&cand_num[i]) { dp.insert(cand_num[i]); from.insert(cand_num[i], (None, i, 1)); } if !dp.contains(&(-cand_num[i])) { dp.insert(-cand_num[i]); from.insert(-cand_num[i], (None, i, -1)); } } if dp.contains(&0) { let mut cur = 0; let mut answers = vec![0; n]; loop { let (prev, idx, sign) = from[&cur]; let i = cand_pos[idx]; answers[i] = a[i] as i64 * sign; if let Some(p) = prev { cur = p; } else { break; } } yes(&answers); } else { println!("No"); } } 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() }