結果

問題 No.1036 Make One With GCD 2
ユーザー akakimidoriakakimidori
提出日時 2020-04-24 21:44:30
言語 Rust
(1.77.0)
結果
AC  
実行時間 629 ms / 2,000 ms
コード長 784 bytes
コンパイル時間 10,365 ms
コンパイル使用メモリ 137,228 KB
実行使用メモリ 18,232 KB
最終ジャッジ日時 2023-10-14 19:15:11
合計ジャッジ時間 18,097 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
18,212 KB
testcase_01 AC 46 ms
10,032 KB
testcase_02 AC 59 ms
18,220 KB
testcase_03 AC 6 ms
4,372 KB
testcase_04 AC 10 ms
4,372 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 19 ms
5,864 KB
testcase_08 AC 15 ms
4,372 KB
testcase_09 AC 132 ms
9,956 KB
testcase_10 AC 119 ms
9,996 KB
testcase_11 AC 136 ms
10,000 KB
testcase_12 AC 123 ms
10,028 KB
testcase_13 AC 271 ms
18,180 KB
testcase_14 AC 267 ms
18,200 KB
testcase_15 AC 253 ms
18,220 KB
testcase_16 AC 262 ms
18,208 KB
testcase_17 AC 273 ms
18,216 KB
testcase_18 AC 1 ms
4,372 KB
testcase_19 AC 1 ms
4,372 KB
testcase_20 AC 1 ms
4,368 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 268 ms
18,224 KB
testcase_23 AC 194 ms
10,040 KB
testcase_24 AC 262 ms
18,220 KB
testcase_25 AC 238 ms
9,956 KB
testcase_26 AC 245 ms
10,060 KB
testcase_27 AC 1 ms
4,368 KB
testcase_28 AC 1 ms
4,368 KB
testcase_29 AC 1 ms
4,372 KB
testcase_30 AC 1 ms
4,368 KB
testcase_31 AC 1 ms
4,368 KB
testcase_32 AC 1 ms
4,368 KB
testcase_33 AC 1 ms
4,368 KB
testcase_34 AC 1 ms
4,368 KB
testcase_35 AC 1 ms
4,372 KB
testcase_36 AC 1 ms
4,368 KB
testcase_37 AC 1 ms
4,368 KB
testcase_38 AC 629 ms
18,220 KB
testcase_39 AC 72 ms
18,108 KB
testcase_40 AC 189 ms
10,028 KB
testcase_41 AC 77 ms
18,184 KB
testcase_42 AC 77 ms
18,224 KB
testcase_43 AC 79 ms
18,232 KB
testcase_44 AC 77 ms
18,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

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

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    it.next();
    let mut ans = 0;
    let mut stack = vec![];
    for s in it {
        let a: u64 = s.parse().unwrap();
        stack.push((a, 1u64));
        for p in stack.iter_mut() {
            p.0 = gcd(p.0, a);
        }
        stack.dedup_by(|a, b| {
            let cond = a.0 == b.0;
            if cond {
                b.1 += a.1;
            }
            cond
        });
        if stack[0].0 == 1 {
            ans += stack[0].1;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}
0