結果
問題 | No.1884 Sequence |
ユーザー |
|
提出日時 | 2022-10-10 20:49:05 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 47 ms / 2,000 ms |
コード長 | 1,214 bytes |
コンパイル時間 | 15,553 ms |
コンパイル使用メモリ | 378,332 KB |
実行使用メモリ | 9,124 KB |
最終ジャッジ日時 | 2024-06-24 17:43:10 |
合計ジャッジ時間 | 16,508 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
コンパイルメッセージ
warning: unused variable: `n` --> src/main.rs:11:9 | 11 | let n: usize = n.trim().parse().unwrap(); | ^ help: if this is intentional, prefix it with an underscore: `_n` | = note: `#[warn(unused_variables)]` on by default
ソースコード
use std::collections::HashSet; fn gcd(a: usize, b: usize) -> usize { if b == 0 { return a; } gcd(b, a % b) } fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let mut a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); a.sort(); let mut zero_cnts = a.iter().filter(|&&v| v == 0).count() as isize; let a = a.into_iter().filter(|&v| v > 0).collect::<Vec<_>>(); if a.len() < 2 { println!("Yes"); return; } let aset = a.iter().copied().collect::<HashSet<_>>(); if aset.len() == 1 { println!("Yes"); return; } let start = a[0]; let a = a.into_iter().map(|v| v - start).collect::<Vec<_>>(); let base = (1..a.len()).fold(a[0], |x, i| gcd(x, a[i])); for i in 0..a.len()-1 { let diff = a[i+1] - a[i]; if diff == 0 { println!("No"); return; } zero_cnts -= (diff / base - 1) as isize; } if zero_cnts < 0 { println!("No"); } else { println!("Yes"); } }