結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー koba-e964koba-e964
提出日時 2021-11-05 23:55:52
言語 Rust
(1.77.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,747 bytes
コンパイル時間 904 ms
コンパイル使用メモリ 174,572 KB
実行使用メモリ 20,684 KB
最終ジャッジ日時 2024-04-25 17:36:17
合計ジャッジ時間 4,048 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
12,820 KB
testcase_01 AC 37 ms
9,628 KB
testcase_02 AC 38 ms
9,692 KB
testcase_03 AC 49 ms
15,972 KB
testcase_04 AC 50 ms
15,920 KB
testcase_05 AC 49 ms
15,840 KB
testcase_06 AC 49 ms
15,916 KB
testcase_07 AC 47 ms
13,992 KB
testcase_08 AC 38 ms
9,624 KB
testcase_09 AC 42 ms
13,752 KB
testcase_10 AC 40 ms
13,992 KB
testcase_11 AC 37 ms
9,748 KB
testcase_12 AC 38 ms
9,628 KB
testcase_13 AC 83 ms
20,632 KB
testcase_14 AC 80 ms
20,608 KB
testcase_15 AC 79 ms
20,572 KB
testcase_16 AC 81 ms
20,684 KB
testcase_17 AC 85 ms
20,636 KB
testcase_18 AC 64 ms
15,696 KB
testcase_19 AC 67 ms
14,372 KB
testcase_20 AC 65 ms
17,212 KB
testcase_21 AC 67 ms
17,212 KB
testcase_22 AC 63 ms
14,816 KB
testcase_23 AC 59 ms
12,860 KB
testcase_24 AC 57 ms
12,764 KB
testcase_25 AC 64 ms
15,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););}
    input! {
        n: usize,
        a: [usize; n],
    }
    const W: usize = 1_000_001;
    let mut f = vec![0; W];
    for &a in &a {
        f[a] += 1;
    }
    let mut div = vec![0; W];
    for i in 1..W {
        for j in 1..(W - 1) / i + 1 {
            div[i] += f[i * j];
        }
    }
    let mut ans = vec![0; n];
    for i in 1..W {
        let idx = n - div[i];
        if idx < n {
            ans[idx] = max(ans[idx], i);
        }
    }
    for i in 1..n {
        ans[i] = max(ans[i], ans[i - 1]);
    }
    for i in 0..n {
        puts!("{}\n", ans[i]);
    }
}
0