結果

問題 No.1884 Sequence
ユーザー RaffRaff
提出日時 2022-04-08 10:35:03
言語 Rust
(1.77.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 2,599 bytes
コンパイル時間 26,860 ms
コンパイル使用メモリ 376,464 KB
実行使用メモリ 6,668 KB
最終ジャッジ日時 2024-05-06 01:56:17
合計ジャッジ時間 13,995 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 51 ms
6,624 KB
testcase_11 AC 48 ms
6,620 KB
testcase_12 AC 8 ms
5,376 KB
testcase_13 AC 9 ms
5,376 KB
testcase_14 AC 8 ms
5,376 KB
testcase_15 AC 27 ms
5,376 KB
testcase_16 AC 41 ms
6,624 KB
testcase_17 AC 15 ms
5,376 KB
testcase_18 AC 19 ms
5,376 KB
testcase_19 AC 17 ms
5,376 KB
testcase_20 AC 24 ms
5,376 KB
testcase_21 AC 17 ms
5,376 KB
testcase_22 AC 26 ms
5,376 KB
testcase_23 AC 43 ms
6,628 KB
testcase_24 AC 40 ms
6,508 KB
testcase_25 AC 40 ms
6,628 KB
testcase_26 AC 41 ms
6,624 KB
testcase_27 AC 9 ms
5,376 KB
testcase_28 AC 9 ms
5,376 KB
testcase_29 AC 9 ms
5,376 KB
testcase_30 AC 9 ms
5,376 KB
testcase_31 AC 22 ms
5,376 KB
testcase_32 AC 38 ms
6,668 KB
testcase_33 AC 25 ms
6,496 KB
testcase_34 AC 25 ms
6,496 KB
testcase_35 AC 11 ms
5,376 KB
testcase_36 AC 22 ms
5,376 KB
testcase_37 AC 26 ms
6,496 KB
testcase_38 AC 25 ms
6,496 KB
testcase_39 AC 14 ms
5,376 KB
testcase_40 AC 14 ms
5,376 KB
testcase_41 AC 36 ms
5,716 KB
testcase_42 AC 34 ms
5,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


macro_rules! chmax {
    ($a: expr, $b: expr) => {
        if $a < $b [
            $a = $b;
        ]
    }
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => (::std::cmp::min($x, min!($($z),*)));
}
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => (::std::cmp::max($x, max!($($z),*)));
}

fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        return a
    }
    gcd(b, a % b)
} 

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut c = vec![];
    for x in a {
        if x != 0 {
            c.push(x);
        }
    }
    let k = c.len();
    if k == 0 {
        println!("Yes");
        return;
    }
    c.sort();
    let mut d = vec![];
    for i in 1..k {
        d.push(c[i] - c[i-1]);
    }
    let cnt = d.iter().filter(|&x| *x == 0).count();
    if cnt > 0 {
        if cnt == k-1 {
            println!("Yes");
        } else {
            println!("No");
        }
        return;
    }

    let g = d.iter().fold(0, |g, x| gcd(g, *x));
    let v = d.iter().fold(0, |tot, x| tot + x / g - 1);

    if v <= n - k {
        println!("Yes");
    } else {
        println!("No");
    }
} 
0