結果
問題 | No.1884 Sequence |
ユーザー |
![]() |
提出日時 | 2022-03-26 11:48:12 |
言語 | Rust (1.83.0 + proconio) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,497 bytes |
コンパイル時間 | 12,802 ms |
コンパイル使用メモリ | 379,244 KB |
実行使用メモリ | 8,192 KB |
最終ジャッジ日時 | 2024-10-15 03:43:00 |
合計ジャッジ時間 | 15,748 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 WA * 5 RE * 2 |
ソースコード
#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[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 main() { let n = read::<usize>(); let mut a = read_vec::<i64>(); a.sort(); let mut zero_count = a.iter().filter(|&&x| x == 0).count() as i64; if zero_count == n as i64 { println!("Yes"); return; } let a = a.iter().filter(|&&x| x > 0).collect::<Vec<_>>(); let diffs = (0..a.len() - 1) .map(|x| a[x + 1] - a[x]) .collect::<Vec<_>>(); let g = diffs.iter().fold(diffs[0], |x, s| gcd(x, *s)); if g == 0 { println!("Yes"); return; } debug!(g); for i in 1..a.len() { zero_count -= (a[i] - a[i - 1]) / g - 1; } if zero_count >= 0 { println!("Yes"); } else { println!("No"); } } fn gcd(a: i64, b: i64) -> i64 { if b == 0 { return a; } gcd(b, a % b) } 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() }