結果

問題 No.1884 Sequence
ユーザー fukafukatanifukafukatani
提出日時 2022-03-26 11:48:12
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 1,497 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 170,532 KB
実行使用メモリ 8,276 KB
最終ジャッジ日時 2024-04-23 04:09:46
合計ジャッジ時間 3,783 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 RE -
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,944 KB
testcase_09 WA -
testcase_10 AC 48 ms
8,192 KB
testcase_11 AC 48 ms
8,244 KB
testcase_12 AC 7 ms
6,940 KB
testcase_13 AC 8 ms
6,940 KB
testcase_14 AC 13 ms
6,940 KB
testcase_15 AC 34 ms
6,940 KB
testcase_16 AC 43 ms
8,192 KB
testcase_17 AC 14 ms
6,940 KB
testcase_18 AC 21 ms
6,940 KB
testcase_19 AC 17 ms
6,940 KB
testcase_20 AC 32 ms
6,944 KB
testcase_21 AC 26 ms
6,940 KB
testcase_22 AC 34 ms
6,944 KB
testcase_23 AC 47 ms
8,192 KB
testcase_24 AC 43 ms
8,192 KB
testcase_25 AC 42 ms
7,716 KB
testcase_26 AC 44 ms
8,192 KB
testcase_27 AC 7 ms
6,940 KB
testcase_28 RE -
testcase_29 AC 7 ms
6,940 KB
testcase_30 AC 9 ms
6,944 KB
testcase_31 AC 31 ms
6,940 KB
testcase_32 WA -
testcase_33 AC 25 ms
8,192 KB
testcase_34 AC 25 ms
8,276 KB
testcase_35 AC 19 ms
6,940 KB
testcase_36 AC 32 ms
6,940 KB
testcase_37 AC 27 ms
8,192 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 40 ms
6,944 KB
testcase_42 AC 40 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![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()
}
0