結果

問題 No.609 Noelちゃんと星々
ユーザー @abcde@abcde
提出日時 2019-06-22 23:02:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 1,542 ms
コンパイル使用メモリ 166,520 KB
実行使用メモリ 4,540 KB
最終ジャッジ日時 2023-08-27 03:20:22
合計ジャッジ時間 3,163 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
4,380 KB
testcase_01 AC 10 ms
4,376 KB
testcase_02 AC 7 ms
4,380 KB
testcase_03 AC 9 ms
4,376 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 22 ms
4,380 KB
testcase_06 AC 19 ms
4,376 KB
testcase_07 AC 12 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 14 ms
4,376 KB
testcase_11 AC 13 ms
4,384 KB
testcase_12 AC 16 ms
4,380 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 19 ms
4,384 KB
testcase_16 AC 23 ms
4,384 KB
testcase_17 AC 18 ms
4,380 KB
testcase_18 AC 7 ms
4,380 KB
testcase_19 AC 19 ms
4,380 KB
testcase_20 AC 23 ms
4,468 KB
testcase_21 AC 24 ms
4,388 KB
testcase_22 AC 23 ms
4,540 KB
testcase_23 AC 23 ms
4,380 KB
testcase_24 AC 23 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// ※※※ 解答不能 ※※※.
// -> 知識問題として, 解法を暗記.
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main() {
    
    // 1. 入力情報取得.
    LL N;
    scanf("%llu", &N);
    LL Y[N];
    for(int i = 0; i < N; i++) scanf("%llu", &Y[i]);
    
    // 2. 昇順sort.
    sort(Y, Y + N);
    
    // 3. Noelちゃんが動かす必要のある距離の総和の最小値 を 計算する.
    LL m = Y[N / 2];
    
    // 4. 集計.
    LL ans = 0;
    for(int i = 0; i < N; i++) ans += abs(Y[i] - m);
    
    // 5. 出力.
    printf("%llu\n", ans);
    return 0;
    
}
0