結果
問題 | No.1884 Sequence |
ユーザー | cympfh |
提出日時 | 2022-05-19 02:05:32 |
言語 | Rust (1.83.0 + proconio) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,778 bytes |
コンパイル時間 | 11,403 ms |
コンパイル使用メモリ | 398,540 KB |
実行使用メモリ | 16,580 KB |
最終ジャッジ日時 | 2024-09-17 06:27:34 |
合計ジャッジ時間 | 15,636 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 0 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | RE | - |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | RE | - |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | WA | - |
testcase_10 | AC | 34 ms
15,744 KB |
testcase_11 | AC | 32 ms
15,872 KB |
testcase_12 | AC | 16 ms
11,700 KB |
testcase_13 | AC | 18 ms
12,848 KB |
testcase_14 | AC | 16 ms
11,576 KB |
testcase_15 | AC | 31 ms
14,592 KB |
testcase_16 | AC | 36 ms
16,000 KB |
testcase_17 | AC | 26 ms
14,396 KB |
testcase_18 | AC | 30 ms
14,720 KB |
testcase_19 | AC | 25 ms
12,672 KB |
testcase_20 | AC | 29 ms
14,400 KB |
testcase_21 | AC | 27 ms
14,368 KB |
testcase_22 | AC | 32 ms
14,396 KB |
testcase_23 | AC | 35 ms
15,872 KB |
testcase_24 | AC | 35 ms
15,872 KB |
testcase_25 | AC | 33 ms
15,872 KB |
testcase_26 | AC | 36 ms
15,872 KB |
testcase_27 | AC | 20 ms
14,392 KB |
testcase_28 | AC | 19 ms
14,472 KB |
testcase_29 | AC | 20 ms
14,396 KB |
testcase_30 | AC | 19 ms
14,396 KB |
testcase_31 | AC | 26 ms
12,416 KB |
testcase_32 | AC | 35 ms
15,744 KB |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | AC | 31 ms
15,872 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 25 ms
14,400 KB |
testcase_41 | AC | 32 ms
15,360 KB |
testcase_42 | AC | 33 ms
15,232 KB |
ソースコード
#![allow(unused_imports, unused_macros, dead_code)] use std::{cmp::*, collections::*}; fn main() { let mut sc = Scanner::new(); let n: usize = sc.cin(); let xs: Vec<u64> = sc.vec(n); let m = xs.iter().filter(|&&x| x > 0).count(); if m <= 2 { put!("Yes"); return; } let mini = *xs.iter().filter(|&&x| x > 0).min().unwrap(); trace!(mini); let mut zs = vec![]; for &x in xs.iter().filter(|&&x| x > mini) { let z = x - mini; zs.push(z); } trace!(&zs); let mut g = zs[0]; for i in 1..zs.len() { g = gcd(g, zs[i]); } trace!(g); let mut ans = "Yes"; let mut used = vec![false; n]; for &z in zs.iter() { let idx = (z / g) as usize; if 1 <= idx && idx < n { if used[idx] { ans = "No"; break; } used[idx] = true; } else { ans = "No"; break; } } put!(ans); } // @num/gcd // @num/base pub trait Zero { fn zero() -> Self; } pub trait One { fn one() -> Self; } pub trait Num: Copy + Eq + Ord + Zero + One + std::marker::Sized + std::ops::Add<Output = Self> + std::ops::AddAssign + std::ops::Sub<Output = Self> + std::ops::SubAssign + std::ops::Mul<Output = Self> + std::ops::Div<Output = Self> + std::ops::Rem<Output = Self> { } pub trait Int: Num {} pub trait Nat: Num {} macro_rules! define_zero_one { ($ty:ty, $zero:expr, $one:expr) => { impl Zero for $ty { fn zero() -> Self { $zero } } impl One for $ty { fn one() -> Self { $one } } }; } define_zero_one!(usize, 0, 1); define_zero_one!(u32, 0, 1); define_zero_one!(u64, 0, 1); define_zero_one!(u128, 0, 1); define_zero_one!(i32, 0, 1); define_zero_one!(i64, 0, 1); define_zero_one!(i128, 0, 1); define_zero_one!(f32, 0.0, 1.0); define_zero_one!(f64, 0.0, 1.0); impl Num for usize {} impl Num for u32 {} impl Num for u64 {} impl Num for u128 {} impl Num for i32 {} impl Num for i64 {} impl Num for i128 {} impl Nat for usize {} impl Nat for u32 {} impl Nat for u64 {} impl Nat for u128 {} impl Int for i32 {} impl Int for i64 {} impl Int for i128 {} /// Number - GCD on Natural Numbers pub fn gcd<N: Nat>(a: N, b: N) -> N { if b == N::zero() { a } else { gcd(b, a % b) } } // {{{ use std::io::{self, Write}; use std::str::FromStr; pub struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, } impl Scanner { pub fn new() -> Self { Self { stdin: io::stdin(), buffer: VecDeque::new(), } } pub fn cin<T: FromStr>(&mut self) -> T { while self.buffer.is_empty() { let mut line = String::new(); let _ = self.stdin.read_line(&mut line); for w in line.split_whitespace() { self.buffer.push_back(String::from(w)); } } self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap() } pub fn usize1(&mut self) -> usize { self.cin::<usize>() - 1 } pub fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() } pub fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() } } fn flush() { std::io::stdout().flush().unwrap(); } #[macro_export] macro_rules! min { (.. $x:expr) => {{ let mut it = $x.iter(); it.next().map(|z| it.fold(z, |x, y| min!(x, y))) }}; ($x:expr) => ($x); ($x:expr, $($ys:expr),*) => {{ let t = min!($($ys),*); if $x < t { $x } else { t } }} } #[macro_export] macro_rules! max { (.. $x:expr) => {{ let mut it = $x.iter(); it.next().map(|z| it.fold(z, |x, y| max!(x, y))) }}; ($x:expr) => ($x); ($x:expr, $($ys:expr),*) => {{ let t = max!($($ys),*); if $x > t { $x } else { t } }} } #[macro_export] macro_rules! trace { ($x:expr) => { #[cfg(debug_assertions)] eprintln!(">>> {} = {:?}", stringify!($x), $x) }; ($($xs:expr),*) => { trace!(($($xs),*)) } } #[macro_export] macro_rules! put { (.. $x:expr) => {{ let mut it = $x.iter(); if let Some(x) = it.next() { print!("{}", x); } for x in it { print!(" {}", x); } println!(""); }}; ($x:expr) => { println!("{}", $x) }; ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) } } #[macro_export] macro_rules! ndarray { ($x:expr;) => { $x }; ($x:expr; $size:expr $( , $rest:expr )*) => { vec![ndarray!($x; $($rest),*); $size] }; } // }}}