結果

問題 No.2811 Calculation Within Sequence
ユーザー sakikuroesakikuroe
提出日時 2024-07-19 21:56:19
言語 Rust
(1.77.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,399 bytes
コンパイル時間 23,169 ms
コンパイル使用メモリ 378,288 KB
実行使用メモリ 9,344 KB
最終ジャッジ日時 2024-07-19 21:56:49
合計ジャッジ時間 17,171 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 28 ms
8,960 KB
testcase_04 AC 27 ms
8,960 KB
testcase_05 AC 25 ms
8,960 KB
testcase_06 AC 26 ms
8,960 KB
testcase_07 AC 24 ms
8,960 KB
testcase_08 AC 26 ms
8,960 KB
testcase_09 AC 26 ms
9,088 KB
testcase_10 AC 26 ms
8,960 KB
testcase_11 AC 24 ms
8,960 KB
testcase_12 AC 28 ms
8,960 KB
testcase_13 AC 29 ms
8,832 KB
testcase_14 AC 28 ms
8,960 KB
testcase_15 AC 28 ms
8,960 KB
testcase_16 AC 28 ms
8,960 KB
testcase_17 AC 27 ms
9,088 KB
testcase_18 AC 28 ms
9,088 KB
testcase_19 AC 24 ms
8,960 KB
testcase_20 AC 27 ms
8,960 KB
testcase_21 AC 29 ms
8,960 KB
testcase_22 AC 26 ms
8,960 KB
testcase_23 AC 26 ms
9,344 KB
testcase_24 AC 16 ms
6,016 KB
testcase_25 AC 6 ms
5,376 KB
testcase_26 AC 7 ms
5,376 KB
testcase_27 AC 16 ms
6,272 KB
testcase_28 AC 4 ms
5,376 KB
testcase_29 AC 14 ms
5,376 KB
testcase_30 AC 13 ms
5,376 KB
testcase_31 AC 15 ms
5,376 KB
testcase_32 AC 5 ms
5,376 KB
testcase_33 AC 12 ms
5,376 KB
testcase_34 AC 15 ms
6,016 KB
testcase_35 AC 8 ms
5,376 KB
testcase_36 AC 12 ms
5,376 KB
testcase_37 AC 9 ms
5,376 KB
testcase_38 AC 10 ms
5,376 KB
testcase_39 AC 10 ms
5,376 KB
testcase_40 AC 15 ms
5,376 KB
testcase_41 AC 16 ms
6,144 KB
testcase_42 AC 7 ms
5,376 KB
testcase_43 AC 11 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use anmitsu::number_theory::gcd;
use proconio::{fastout, input};

pub mod anmitsu {
    pub mod number_theory {
        /// Returns:
        ///     gcd(a, b)
        ///
        /// Note:
        ///     gcd(0, 0) = 0
        ///     gcd(a, 0) = a
        ///     gcd(a, b) >= 0
        ///     gcd(a, a) == abs(a)
        ///     gcd(a, b) == gcd(b, a)
        ///
        /// Complexity:
        ///     O(log(min(abs(a), abs(b))))
        ///
        /// Exsamples:
        /// ```
        /// use anmitsu::math::number_theory::gcd;
        /// assert_eq!(gcd(0, 0), 0);
        /// assert_eq!(gcd(0, 1), 1);
        /// assert_eq!(gcd(4, 6), 2);
        /// assert_eq!(gcd(4, -6), 2);
        /// assert_eq!(gcd(-4, 6), 2);
        /// assert_eq!(gcd(-4, -6), 2);
        /// assert_eq!(gcd(2, 2), 2);
        /// assert_eq!(gcd(-2, -2), 2);
        /// ```
        pub fn gcd(mut a: i64, mut b: i64) -> u64 {
            while b != 0 {
                (a, b) = (b, a % b);
            }
            a.unsigned_abs()
        }
    }
}

#[fastout]
fn main() {
    input! {
        a: usize, b: usize,
        t: [usize; a],
        s: [usize; b],
    }

    let mut g = t[0];
    for i in 1..a {
        g = gcd(g as i64, t[i] as i64) as usize;
    }

    if (0..a).any(|i| t[i].abs_diff(*s.get(i).unwrap_or(&0)) % g != 0) {
        println!("No");
    } else {
        println!("Yes");
    }
}
0