結果
問題 |
No.2811 Calculation Within Sequence
|
ユーザー |
![]() |
提出日時 | 2024-11-11 17:07:09 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 26 ms / 2,000 ms |
コード長 | 1,293 bytes |
コンパイル時間 | 24,248 ms |
コンパイル使用メモリ | 378,652 KB |
実行使用メモリ | 9,344 KB |
最終ジャッジ日時 | 2024-11-11 17:07:40 |
合計ジャッジ時間 | 24,981 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#![allow(non_snake_case, unused_must_use, unused_imports)] use std::io::{self, prelude::*}; fn main() { let (stdin, stdout) = (io::read_to_string(io::stdin()).unwrap(), io::stdout()); let (mut stdin, mut buffer) = (stdin.split_whitespace(), io::BufWriter::new(stdout.lock())); macro_rules! input { ($t: tt, $n: expr) => { (0..$n).map(|_| input!($t)).collect::<Vec<_>>() }; (Chars) => { input! {String}.chars().collect::<Vec<_>>() }; (Usize1) => { stdin.next().unwrap().parse::<usize>().unwrap() - 1 }; ($t: ty) => { stdin.next().unwrap().parse::<$t>().unwrap() }; } let a = input!(usize); let b = input!(usize); let T = input!(usize, a); let S = input!(usize, b); let mut g = T[0]; for i in 1..a { g = gcd(g, T[i]); } let mut isok = true; for i in 0..(std::cmp::min(a, b)) { if T[i].abs_diff(S[i]) % g != 0 { isok = false; break; } } writeln!(buffer, "{}", if isok { "Yes" } else { "No" }); } fn gcd(a: usize, b: usize) -> usize { if a < b { return gcd(b, a); } if b == 0 { return a; } else { return gcd(b, a % b); } }