結果

問題 No.1884 Sequence
ユーザー RaffRaff
提出日時 2022-04-08 10:32:14
言語 Rust
(1.77.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,486 bytes
コンパイル時間 25,406 ms
コンパイル使用メモリ 378,536 KB
実行使用メモリ 9,860 KB
最終ジャッジ日時 2024-05-06 01:55:24
合計ジャッジ時間 15,771 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 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 39 ms
9,860 KB
testcase_11 AC 38 ms
9,728 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 22 ms
6,016 KB
testcase_16 AC 35 ms
9,716 KB
testcase_17 AC 10 ms
5,376 KB
testcase_18 AC 14 ms
6,400 KB
testcase_19 AC 13 ms
5,376 KB
testcase_20 AC 18 ms
5,504 KB
testcase_21 AC 13 ms
5,376 KB
testcase_22 AC 21 ms
5,760 KB
testcase_23 AC 37 ms
9,724 KB
testcase_24 AC 36 ms
9,720 KB
testcase_25 AC 35 ms
9,516 KB
testcase_26 AC 34 ms
9,572 KB
testcase_27 AC 5 ms
5,376 KB
testcase_28 AC 5 ms
5,376 KB
testcase_29 AC 4 ms
5,376 KB
testcase_30 AC 5 ms
5,376 KB
testcase_31 AC 17 ms
5,376 KB
testcase_32 AC 34 ms
9,580 KB
testcase_33 AC 18 ms
9,620 KB
testcase_34 AC 18 ms
9,624 KB
testcase_35 AC 5 ms
5,376 KB
testcase_36 AC 14 ms
6,656 KB
testcase_37 AC 20 ms
9,748 KB
testcase_38 AC 19 ms
9,356 KB
testcase_39 AC 8 ms
5,376 KB
testcase_40 AC 8 ms
5,376 KB
testcase_41 AC 29 ms
7,988 KB
testcase_42 AC 28 ms
8,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports, dead_code)]
#![allow(unused_macros)]
use proconio::{input, marker::{Chars, Usize1}};

// use std::cmp::{max, min, Reverse};
use std::mem::{swap};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque, LinkedList};

use std::cmp::Ordering;

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