結果

問題 No.1006 Share an Integer
ユーザー phsplsphspls
提出日時 2020-07-08 23:14:12
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 764 bytes
コンパイル時間 1,113 ms
コンパイル使用メモリ 163,888 KB
実行使用メモリ 17,416 KB
最終ジャッジ日時 2024-04-15 08:38:44
合計ジャッジ時間 3,371 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 73 ms
10,536 KB
testcase_12 AC 168 ms
16,624 KB
testcase_13 AC 187 ms
17,280 KB
testcase_14 AC 173 ms
17,416 KB
testcase_15 AC 116 ms
15,232 KB
testcase_16 AC 43 ms
8,456 KB
testcase_17 AC 83 ms
10,752 KB
testcase_18 AC 131 ms
15,344 KB
testcase_19 AC 127 ms
14,816 KB
testcase_20 AC 124 ms
15,872 KB
testcase_21 AC 174 ms
17,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::{min, max};

fn calc(i: usize, x: usize, d: &Vec<usize>) -> usize {
    let a = i - d[i];
    let b = x - i - d[x-i];
    max(a, b) - min(a, b)
}

fn main() {
    let mut x = String::new();
    std::io::stdin().read_line(&mut x).ok();
    let x: usize = x.trim().parse().unwrap();

    let mut divs: Vec<usize> = vec![2; x+1];
    divs[0] = 0;
    divs[1] = 1;
    for i in 2..=x/2 {
        for j in 2..=x/i {
            divs[i*j] += 1;
        }
    }
    let mut minval: usize = x;
    for i in 0..=x/2 {
        minval = min(minval, calc(i, x, &divs));
    }
    (0..=x)
        .map(|i| calc(i, x, &divs))
        .enumerate()
        .filter(|pair| pair.1 == minval)
        .for_each(|pair| { println!("{} {}", pair.0, x - pair.0); })
    ;
}
0