結果

問題 No.1006 Share an Integer
ユーザー phsplsphspls
提出日時 2020-06-03 19:16:06
言語 Rust
(1.72.1)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 686 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 145,564 KB
実行使用メモリ 48,860 KB
最終ジャッジ日時 2023-08-16 18:29:51
合計ジャッジ時間 3,506 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 66 ms
27,908 KB
testcase_12 AC 120 ms
46,272 KB
testcase_13 AC 131 ms
48,860 KB
testcase_14 AC 129 ms
48,856 KB
testcase_15 AC 109 ms
41,916 KB
testcase_16 AC 45 ms
21,480 KB
testcase_17 AC 64 ms
28,560 KB
testcase_18 AC 112 ms
42,464 KB
testcase_19 AC 106 ms
40,684 KB
testcase_20 AC 113 ms
43,400 KB
testcase_21 AC 131 ms
48,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    let mut d: Vec<usize> = vec![0; x+1];
    for i in 1..x {
        for j in 1..=x/i {
            d[i*j] += 1;
        }
    }
    let f: Vec<usize> = (0..=x).map(|i| i - d[i]).collect();
    let f: Vec<usize> = (0..=x).map(|i| max(f[i], f[x-i]) - min(f[i], f[x-i])).collect();
    let minval: usize = f.iter().map(|i| *i).min().unwrap();
    f.iter().enumerate().for_each(|pair| {
        let i = *pair.1;
        let j = pair.0;
        if i == minval {
            println!("{} {}", j, x-j);
        }
    });
}
0