結果

問題 No.1006 Share an Integer
ユーザー phsplsphspls
提出日時 2020-07-08 23:18:30
言語 Rust
(1.77.0)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 771 bytes
コンパイル時間 8,157 ms
コンパイル使用メモリ 150,256 KB
実行使用メモリ 17,476 KB
最終ジャッジ日時 2024-04-15 09:05:34
合計ジャッジ時間 4,877 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 75 ms
10,520 KB
testcase_12 AC 185 ms
16,600 KB
testcase_13 AC 213 ms
17,456 KB
testcase_14 AC 213 ms
17,476 KB
testcase_15 AC 160 ms
15,228 KB
testcase_16 AC 46 ms
8,404 KB
testcase_17 AC 83 ms
10,616 KB
testcase_18 AC 167 ms
15,200 KB
testcase_19 AC 152 ms
14,908 KB
testcase_20 AC 177 ms
15,788 KB
testcase_21 AC 202 ms
17,396 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 1..=x/2 {
        minval = min(minval, calc(i, x, &divs));
    }
    (1..x)
        .map(|i| calc(i, x, &divs))
        .enumerate()
        .filter(|pair| pair.1 == minval)
        .for_each(|pair| { println!("{} {}", pair.0 + 1, x - pair.0 - 1); })
    ;
}
0