結果

問題 No.2811 Calculation Within Sequence
ユーザー sakikuroesakikuroe
提出日時 2024-07-19 21:27:21
言語 Rust
(1.77.0 + proconio)
結果
WA  
実行時間 -
コード長 3,308 bytes
コンパイル時間 15,208 ms
コンパイル使用メモリ 378,192 KB
実行使用メモリ 9,344 KB
最終ジャッジ日時 2024-07-19 21:27:55
合計ジャッジ時間 19,475 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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()
        }

        /// Returns:
        ///     (x, y): (i64, i64)
        ///     s.t.
        ///         - gcd(a, b) = a * x + b * y
        ///         - max(abs(x), abs(y)) <= max(abs(a), abs(b))
        ///
        /// Complexity:
        ///     O(log(min(abs(a), abs(b))))
        ///
        /// References:
        ///     - [超わかりやすい拡張ユークリッドの互除法 - 簡潔なQ](https://qnighy.hatenablog.com/entry/20091230/1262173513)
        ///
        /// Exsamples:
        /// ```
        /// use anmitsu::math::number_theory::extended_gcd;
        ///
        /// // gcd(10, 4) = 2 = 10 * 1 + 4 * (-2)
        /// assert_eq!(extended_gcd(10, 4), (1, -2));
        ///
        /// // gcd(0, 4) = 4 = 0 * 0 + 4 * 1
        /// assert_eq!(extended_gcd(0, 4), (0, 1));
        ///
        /// // gcd(0, 0) = 0 = 0 * 0 + 0 * 0
        /// assert_eq!(extended_gcd(0, 0), (0, 0));
        ///
        /// // gcd(-12, 7) = 1 = -12 * (-3) + 7 * (-5)
        /// assert_eq!(extended_gcd(-12, 7), (-3, -5));
        /// ```
        pub fn extended_gcd(a: i64, b: i64) -> (i64, i64) {
            if a == 0 && b == 0 {
                return (0, 0);
            } else if a == 0 {
                return (0, if b >= 0 { 1 } else { -1 });
            } else if b == 0 {
                return (if a >= 0 { 1 } else { -1 }, 0);
            }

            let (mut xs, mut ys, mut s) = (1, 0, a);
            let (mut xt, mut yt, mut t) = (0, 1, b);

            while s % t != 0 {
                let q = s / t;
                let (u, xu, yu) = (s - q * t, xs - q * xt, ys - q * yt);
                (xs, ys, xt, yt) = (xt, yt, xu, yu);
                (s, t) = (t, u);
            }

            if t < 0 {
                (-xt, -yt)
            } else {
                (xt, yt)
            }
        }
    }
}

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

    if a < b && (a..b).any(|i| s[i] != 0) {
        println!("No");
        return;
    }

    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