結果

問題 No.917 Make One With GCD
ユーザー tonyu0tonyu0
提出日時 2020-03-11 13:28:14
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 954 bytes
コンパイル時間 15,207 ms
コンパイル使用メモリ 387,736 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-27 19:12:00
合計ジャッジ時間 11,864 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 0 ms
6,940 KB
testcase_02 AC 0 ms
6,940 KB
testcase_03 AC 0 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 WA -
testcase_06 AC 0 ms
6,944 KB
testcase_07 WA -
testcase_08 AC 1 ms
6,940 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 0 ms
6,940 KB
testcase_18 WA -
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 WA -
testcase_24 AC 1 ms
6,944 KB
testcase_25 WA -
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 1 ms
6,944 KB
testcase_30 AC 1 ms
6,940 KB
testcase_31 AC 0 ms
6,940 KB
testcase_32 AC 0 ms
6,940 KB
testcase_33 AC 1 ms
6,944 KB
testcase_34 AC 1 ms
6,940 KB
testcase_35 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

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

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<u64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut dp = std::collections::HashMap::new();
    dp.insert(0, 1);
    for i in 0..n {
        let mut next = std::collections::HashMap::new();
        for (&value, &count) in dp.iter() {
            // use
            let g = gcd(value, a[i]);
            let val = next.entry(g).or_insert(0);
            *val += count;
            // not use
            let val = next.entry(value).or_insert(0);
            *val += count;
        }
        dp = next;
    }
    let val = dp.entry(1).or_insert(0);
    println!("{}", *val);
}
0