結果
| 問題 |
No.1884 Sequence
|
| ユーザー |
fukafukatani
|
| 提出日時 | 2022-03-26 13:27:22 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 45 ms / 2,000 ms |
| コード長 | 1,625 bytes |
| コンパイル時間 | 13,658 ms |
| コンパイル使用メモリ | 378,276 KB |
| 実行使用メモリ | 8,320 KB |
| 最終ジャッジ日時 | 2024-10-15 05:20:25 |
| 合計ジャッジ時間 | 14,059 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
#![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 - 1 {
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 diffs.iter().any(|&d| d == 0) {
if a.iter().all(|&x| x == a[0]) {
println!("Yes");
} else {
println!("No");
}
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()
}
fukafukatani