提出 #29973181


ソースコード 拡げる

use proconio::input;

fn f(a: &[i64]) -> i64 {
    let n = a.len() as i64;
    let mut b = a.iter().copied().collect::<Vec<i64>>();
    b.sort();
    b.iter()
        .copied()
        .enumerate()
        .map(|(i, b_i)| i as i64 * b_i - b_i * (n - 1 - i as i64))
        .sum::<i64>()
}

fn main() {
    input! {
        n: usize,
        xy: [(i64, i64); n],
    };
    let sum_x = f(&xy.iter().copied().map(|(x, _)| x).collect::<Vec<i64>>());
    let sum_y = f(&xy.iter().copied().map(|(_, y)| y).collect::<Vec<i64>>());
    let ans = sum_x + sum_y;
    println!("{}", ans);
}

提出情報

提出日時
問題 077 - Distance Sum
ユーザ bouzuya
言語 Rust (1.42.0)
得点 1000
コード長 581 Byte
結果 AC
実行時間 61 ms
メモリ 11456 KiB

ジャッジ結果

セット名 All
得点 / 配点 1000 / 1000
結果
AC × 31
セット名 テストケース
All in01_small, in02_small, in03_small, in04_small, in05_small, in06_small, in07_small, in08_small, in09_small, in10_small, in11_small, in12_small, in13_small, in14_small, in15_small, in16_small, in17_small, in18_small, in19_small, in20_small, in21_large, in22_large, in23_large, in24_large, in25_large, in26_large, in27_large, in28_large, in29_large, in30_large, sample_01
ケース名 結果 実行時間 メモリ
in01_small AC 6 ms 2116 KiB
in02_small AC 2 ms 2068 KiB
in03_small AC 2 ms 2104 KiB
in04_small AC 2 ms 2036 KiB
in05_small AC 1 ms 2100 KiB
in06_small AC 1 ms 1964 KiB
in07_small AC 3 ms 1896 KiB
in08_small AC 2 ms 2072 KiB
in09_small AC 1 ms 2068 KiB
in10_small AC 1 ms 1900 KiB
in11_small AC 2 ms 2016 KiB
in12_small AC 1 ms 2156 KiB
in13_small AC 1 ms 2048 KiB
in14_small AC 1 ms 1980 KiB
in15_small AC 2 ms 2104 KiB
in16_small AC 1 ms 2164 KiB
in17_small AC 1 ms 2048 KiB
in18_small AC 1 ms 1948 KiB
in19_small AC 2 ms 2012 KiB
in20_small AC 2 ms 2088 KiB
in21_large AC 54 ms 11096 KiB
in22_large AC 56 ms 11456 KiB
in23_large AC 58 ms 11088 KiB
in24_large AC 61 ms 11436 KiB
in25_large AC 58 ms 11388 KiB
in26_large AC 55 ms 10996 KiB
in27_large AC 57 ms 11132 KiB
in28_large AC 58 ms 11168 KiB
in29_large AC 61 ms 11188 KiB
in30_large AC 57 ms 11192 KiB
sample_01 AC 1 ms 2084 KiB