結果

問題 No.1884 Sequence
ユーザー phsplsphspls
提出日時 2022-10-10 20:49:05
言語 Rust
(1.77.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,214 bytes
コンパイル時間 1,460 ms
コンパイル使用メモリ 163,824 KB
実行使用メモリ 8,936 KB
最終ジャッジ日時 2023-09-06 23:43:36
合計ジャッジ時間 7,240 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 47 ms
8,936 KB
testcase_11 AC 47 ms
8,936 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 7 ms
4,380 KB
testcase_14 AC 10 ms
4,376 KB
testcase_15 AC 34 ms
6,476 KB
testcase_16 AC 46 ms
8,916 KB
testcase_17 AC 14 ms
5,976 KB
testcase_18 AC 22 ms
6,660 KB
testcase_19 AC 17 ms
6,036 KB
testcase_20 AC 30 ms
6,172 KB
testcase_21 AC 24 ms
5,228 KB
testcase_22 AC 33 ms
6,344 KB
testcase_23 AC 47 ms
8,932 KB
testcase_24 AC 45 ms
8,836 KB
testcase_25 AC 45 ms
8,680 KB
testcase_26 AC 45 ms
8,920 KB
testcase_27 AC 6 ms
4,380 KB
testcase_28 AC 7 ms
4,632 KB
testcase_29 AC 6 ms
4,376 KB
testcase_30 AC 7 ms
4,584 KB
testcase_31 AC 28 ms
5,944 KB
testcase_32 AC 44 ms
8,696 KB
testcase_33 AC 22 ms
7,104 KB
testcase_34 AC 22 ms
7,112 KB
testcase_35 AC 15 ms
4,820 KB
testcase_36 AC 28 ms
6,288 KB
testcase_37 AC 28 ms
7,028 KB
testcase_38 AC 23 ms
6,716 KB
testcase_39 AC 20 ms
5,128 KB
testcase_40 AC 22 ms
5,212 KB
testcase_41 AC 41 ms
8,220 KB
testcase_42 AC 40 ms
8,228 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
  --> 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

warning: 1 warning emitted

ソースコード

diff #

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");
    }
}
0