結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー koba-e964koba-e964
提出日時 2023-07-11 09:58:44
言語 Rust
(1.77.0)
結果
AC  
実行時間 41 ms / 4,000 ms
コード長 1,618 bytes
コンパイル時間 2,301 ms
コンパイル使用メモリ 154,304 KB
実行使用メモリ 6,680 KB
最終ジャッジ日時 2023-10-10 01:43:18
合計ジャッジ時間 4,094 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,144 KB
testcase_01 AC 11 ms
5,104 KB
testcase_02 AC 11 ms
5,048 KB
testcase_03 AC 11 ms
5,060 KB
testcase_04 AC 11 ms
5,108 KB
testcase_05 AC 11 ms
5,144 KB
testcase_06 AC 10 ms
5,060 KB
testcase_07 AC 11 ms
5,136 KB
testcase_08 AC 12 ms
6,680 KB
testcase_09 AC 13 ms
6,680 KB
testcase_10 AC 13 ms
6,676 KB
testcase_11 AC 13 ms
6,620 KB
testcase_12 AC 13 ms
6,652 KB
testcase_13 AC 24 ms
6,452 KB
testcase_14 AC 21 ms
6,472 KB
testcase_15 AC 27 ms
6,448 KB
testcase_16 AC 29 ms
6,476 KB
testcase_17 AC 26 ms
6,400 KB
testcase_18 AC 24 ms
5,724 KB
testcase_19 AC 27 ms
6,484 KB
testcase_20 AC 41 ms
6,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
// 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() {
    input! {
        n: usize,
        a: [usize; n],
    }
    const W: usize = 200_001;
    let mut f = vec![0i64; W];
    for a in a {
        f[a] += 1;
    }
    let mut acc = vec![0; W + 1];
    let mut accv = vec![0; W + 1];
    for i in 0..W {
        acc[i + 1] = acc[i] + f[i];
        accv[i + 1] = accv[i] + f[i] * i as i64;
    }
    let mut ans = 0i64;
    for i in 1..W {
        let mut me = 0;
        me += accv[i];
        me -= accv[W] - accv[i];
        for j in 1..(W - 1) / i + 1 {
            me += (j * i) as i64 * (acc[min(W, i * j + i)] - acc[i * j]);
        }
        ans += me * f[i];
    }
    println!("{}", ans);
}
0