結果

問題 No.1391 ±1 Abs Sum
ユーザー trineutrontrineutron
提出日時 2021-02-17 17:34:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 804 bytes
コンパイル時間 2,989 ms
コンパイル使用メモリ 201,160 KB
実行使用メモリ 5,516 KB
最終ジャッジ日時 2023-10-12 04:28:22
合計ジャッジ時間 8,207 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 80 ms
5,388 KB
testcase_12 AC 60 ms
4,972 KB
testcase_13 WA -
testcase_14 AC 46 ms
4,360 KB
testcase_15 AC 49 ms
4,356 KB
testcase_16 AC 61 ms
4,836 KB
testcase_17 AC 54 ms
4,696 KB
testcase_18 AC 73 ms
5,152 KB
testcase_19 WA -
testcase_20 WA -
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 80 ms
5,428 KB
testcase_32 AC 43 ms
4,352 KB
testcase_33 AC 49 ms
4,400 KB
testcase_34 AC 74 ms
5,196 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 85 ms
5,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int n, k;

int64_t calc(const vector<int64_t> &s, int64_t x, int i, int l)
{
    return s.at(l) - l * x - (s.at(i) - s.at(l) - (i - l) * x) + (s.at(l + k) - s.at(i) - (l + k - i) * x) - (s.at(n) - s.at(l + k) - (n - l - k) * x);
}

int main()
{
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    vector<int64_t> s(n + 1);
    for (int i = 0; i < n; i++)
    {
        s.at(i + 1) = s.at(i) + a.at(i);
    }
    int64_t ans = 1e18;
    int l = 0;
    for (int i = 0; i < n; i++)
    {
        while (l < i and l + k <= i and calc(s, a.at(i), i, l) > calc(s, a.at(i), i, l + 1))
        {
            l++;
        }
        ans = min(ans, calc(s, a.at(i), i, l));
    }
    cout << ans << endl;
}
0