結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー phspls
提出日時 2022-11-01 11:29:36
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 819 bytes
コンパイル時間 16,006 ms
コンパイル使用メモリ 393,328 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-16 05:33:45
合計ジャッジ時間 14,547 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

fn gcd(a: usize, b: usize) -> usize {
    if b == 0 { return a; }
    gcd(b, a%b)
}

fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let m = nm[1];
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut b = String::new();
    std::io::stdin().read_line(&mut b).ok();
    let b: Vec<usize> = b.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let gcdval = gcd(n, m);
    for i in 0..n*m/gcdval {
        if a[i%n] == b[i%m] {
            println!("{}", i+1);
            return;
        }
    }
    println!("-1");
}
0