結果

問題 No.1391 ±1 Abs Sum
ユーザー merom686merom686
提出日時 2021-02-12 22:27:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 765 bytes
コンパイル時間 808 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-27 05:03:54
合計ジャッジ時間 2,850 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 22 ms
4,380 KB
testcase_12 AC 17 ms
4,376 KB
testcase_13 AC 22 ms
4,376 KB
testcase_14 AC 13 ms
4,380 KB
testcase_15 AC 14 ms
4,380 KB
testcase_16 AC 17 ms
4,380 KB
testcase_17 AC 16 ms
4,376 KB
testcase_18 AC 20 ms
4,380 KB
testcase_19 AC 15 ms
4,380 KB
testcase_20 AC 22 ms
4,380 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 AC 23 ms
4,376 KB
testcase_32 AC 13 ms
4,380 KB
testcase_33 AC 13 ms
4,380 KB
testcase_34 AC 22 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 25 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;
    k = n - k;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    ll r = 1LL << 60;
    for (int h = 0; h < 2; h++) {
        int x = a[min(k + n / 2, n - 1)];
        ll t = 0;
        for (int i = 0; i < n; i++) {
            t += abs(x - a[i]) * (i < k ? -1 : 1);
        }
        r = min(r, t);

        reverse(a.begin(), a.end());
        for (int i = 0; i < n; i++) {
            a[i] *= -1;
        }
    }

    cout << r << endl;

    return 0;
}
0