結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー phsplsphspls
提出日時 2022-10-16 17:47:13
言語 Rust
(1.77.0)
結果
AC  
実行時間 1,236 ms / 2,000 ms
コード長 1,030 bytes
コンパイル時間 2,201 ms
コンパイル使用メモリ 134,356 KB
実行使用メモリ 14,704 KB
最終ジャッジ日時 2023-09-09 20:01:50
合計ジャッジ時間 13,901 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,236 ms
11,240 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 4 ms
6,524 KB
testcase_03 AC 5 ms
8,612 KB
testcase_04 AC 5 ms
7,336 KB
testcase_05 AC 5 ms
9,040 KB
testcase_06 AC 5 ms
9,092 KB
testcase_07 AC 5 ms
8,960 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 4 ms
6,632 KB
testcase_10 AC 5 ms
6,512 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 814 ms
14,584 KB
testcase_14 AC 811 ms
14,612 KB
testcase_15 AC 811 ms
14,704 KB
testcase_16 AC 807 ms
14,704 KB
testcase_17 AC 805 ms
14,668 KB
testcase_18 AC 508 ms
8,312 KB
testcase_19 AC 1,007 ms
12,516 KB
testcase_20 AC 360 ms
10,752 KB
testcase_21 AC 358 ms
10,748 KB
testcase_22 AC 1,061 ms
11,336 KB
testcase_23 AC 253 ms
5,848 KB
testcase_24 AC 252 ms
10,004 KB
testcase_25 AC 738 ms
12,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const LIMIT: usize = 1e6 as usize;

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    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 used_cnt = vec![0usize; LIMIT + 1];
    for i in 0..n {
        for j in 1..=(a[i] as f64).sqrt().floor() as usize {
            if a[i] % j == 0 {
                let l = j;
                let r = a[i]/j;
                used_cnt[l] += 1;
                if l != r {
                    used_cnt[r] += 1;
                }
            }
        }
    }
    let mut result = vec![0usize; n];
    for i in (1..=LIMIT).rev() {
        if used_cnt[i] == 0 { continue; }
        let mut idx = n-used_cnt[i];
        while idx < n && result[idx] == 0 {
            result[idx] = i;
            idx += 1;
        }
    }
    for &v in result.iter() {
        println!("{}", v);
    }
}
0