結果

問題 No.1233 割り切れない気持ち
ユーザー tzyvrntzyvrn
提出日時 2020-09-19 16:01:17
言語 Rust
(1.77.0 + proconio)
結果
WA  
実行時間 -
コード長 1,694 bytes
コンパイル時間 18,577 ms
コンパイル使用メモリ 382,588 KB
実行使用メモリ 14,544 KB
最終ジャッジ日時 2024-06-23 16:39:44
合計ジャッジ時間 21,209 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,816 KB
testcase_01 AC 5 ms
6,820 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 13 ms
6,944 KB
testcase_18 AC 39 ms
14,412 KB
testcase_19 WA -
testcase_20 AC 12 ms
6,940 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 4 ms
6,944 KB
testcase_38 AC 13 ms
6,944 KB
testcase_39 AC 26 ms
10,176 KB
testcase_40 AC 27 ms
10,308 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `HashSet`
 --> src/main.rs:1:33
  |
1 | use std::collections::{HashMap, HashSet};
  |                                 ^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: use of deprecated method `core::str::<impl str>::trim_right`: superseded by `trim_end`
  --> src/main.rs:10:23
   |
10 |             let s = s.trim_right();
   |                       ^^^^^^^^^^
...
33 |     let n = getl!(usize);
   |             ------------ in this macro invocation
   |
   = note: `#[warn(deprecated)]` on by default
   = note: this warning originates in the macro `getl` (in Nightly builds, run with -Z macro-backtrace for more info)
help: replace the use of the deprecated method
   |
10 |             let s = s.trim_end();
   |                       ~~~~~~~~

warning: use of deprecated method `core::str::<impl str>::trim_right`: superseded by `trim_end`
  --> src/main.rs:22:19
   |
22 |         let s = s.trim_right();
   |                   ^^^^^^^^^^
...
34 |     let mut a = getl_vec!(usize);
   |                 ---------------- in this macro invocation
   |
   = note: this warning originates in the macro `getl_vec` (in Nightly builds, run with -Z macro-backtrace for more info)
help: replace the use of the deprecated method
   |
22 |         let s = s.trim_end();
   |                   ~~~~~~~~

warning: unused variable: `c_i`
  --> src/main.rs:57:15
   |
57 |     for (a_i, c_i) in map {
   |               ^^^ help: if this is intentional, prefix it with an underscore: `_c_i`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: variable does not need to be mutable
  --> src/main.rs:34:9
   |
34 |     let mut a = getl_vec!(usize);
   |         ----^
   |         |
   |         help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

ソースコード

diff #

use std::collections::{HashMap, HashSet};

//{{{
#[allow(unused_macros)]
macro_rules! getl {
    ( $( $t:ty ),* ) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            let s = s.trim_right();
            let mut ws = s.split_whitespace();
            ($(ws.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! getl_vec {
    ( $t:ty ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right();
        s.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect::<Vec<$t>>()
    }};
}
//}}}

const MAX: usize = 300_000;

fn main() {
    let n = getl!(usize);
    let mut a = getl_vec!(usize);

    let mut c = vec![0usize; MAX];
    for a_i in a.iter().copied() {
        c[a_i] += 1;
    }

    let mut sc = vec![0usize];
    for c_i in c {
        let last = sc.last().copied().unwrap();
        sc.push(c_i + last);
    }
    let sc = sc;

    let mut map = HashMap::new();
    for a_i in a.iter().copied() {
        let entry = map.entry(a_i).or_insert(0usize);
        *entry += 1;
    }

    let s: usize = a.iter().sum();

    let mut ans = 0usize;
    for (a_i, c_i) in map {
        let mut now = s;
        let mut m = 0;
        while a_i * m < MAX {
            // dbg!(now, c_i, m, a_i, &sc[..=10]);
            if (m + 1) * a_i < MAX {
                now -= m * a_i * (sc[(m + 1) * a_i] - sc[m * a_i]);
            } else {
                now -= m * a_i * (n - sc[m * a_i]);
            }
            m += 1;
        }
        ans += now;
    }
    println!("{}", ans);
}
0