結果
問題 | No.1884 Sequence |
ユーザー | cympfh |
提出日時 | 2022-05-19 02:07:46 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,913 bytes |
コンパイル時間 | 12,285 ms |
コンパイル使用メモリ | 403,644 KB |
実行使用メモリ | 17,140 KB |
最終ジャッジ日時 | 2024-09-17 06:29:51 |
合計ジャッジ時間 | 15,284 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,812 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | WA | - |
testcase_10 | AC | 40 ms
15,872 KB |
testcase_11 | AC | 40 ms
15,872 KB |
testcase_12 | AC | 18 ms
11,828 KB |
testcase_13 | AC | 20 ms
12,840 KB |
testcase_14 | AC | 20 ms
11,576 KB |
testcase_15 | AC | 39 ms
14,592 KB |
testcase_16 | AC | 43 ms
15,872 KB |
testcase_17 | AC | 30 ms
14,272 KB |
testcase_18 | AC | 33 ms
15,408 KB |
testcase_19 | AC | 29 ms
12,672 KB |
testcase_20 | AC | 35 ms
14,396 KB |
testcase_21 | AC | 31 ms
14,396 KB |
testcase_22 | AC | 37 ms
14,520 KB |
testcase_23 | AC | 43 ms
15,872 KB |
testcase_24 | AC | 43 ms
17,140 KB |
testcase_25 | AC | 42 ms
15,744 KB |
testcase_26 | AC | 41 ms
15,872 KB |
testcase_27 | AC | 21 ms
14,396 KB |
testcase_28 | AC | 21 ms
15,568 KB |
testcase_29 | AC | 22 ms
14,868 KB |
testcase_30 | AC | 23 ms
14,404 KB |
testcase_31 | AC | 31 ms
12,288 KB |
testcase_32 | AC | 43 ms
15,744 KB |
testcase_33 | AC | 34 ms
16,000 KB |
testcase_34 | AC | 34 ms
16,000 KB |
testcase_35 | AC | 23 ms
15,044 KB |
testcase_36 | AC | 33 ms
14,976 KB |
testcase_37 | AC | 39 ms
16,896 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 31 ms
14,396 KB |
testcase_41 | AC | 40 ms
15,232 KB |
testcase_42 | AC | 41 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(); let maxi = *xs.iter().filter(|&&x| x > 0).max().unwrap(); trace!(mini, maxi); if mini == maxi { put!("Yes"); return; } 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] }; } // }}}