結果

問題 No.1248 Kth Sum
ユーザー 👑 NachiaNachia
提出日時 2020-10-02 22:29:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,029 bytes
コンパイル時間 3,679 ms
コンパイル使用メモリ 169,776 KB
実行使用メモリ 47,356 KB
最終ジャッジ日時 2023-09-24 21:38:46
合計ジャッジ時間 7,236 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
44,332 KB
testcase_01 AC 10 ms
44,328 KB
testcase_02 AC 10 ms
44,284 KB
testcase_03 AC 10 ms
44,316 KB
testcase_04 AC 10 ms
44,268 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 10 ms
44,444 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 98 ms
47,096 KB
testcase_14 WA -
testcase_15 AC 98 ms
47,092 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 9 ms
42,456 KB
testcase_24 WA -
testcase_25 AC 103 ms
47,156 KB
testcase_26 WA -
testcase_27 AC 99 ms
46,568 KB
testcase_28 AC 100 ms
46,684 KB
testcase_29 AC 106 ms
47,220 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int N, K;
LL A[200000];
int P[18][200000] = {};
LL S[18][200000] = {};

LL getsum(int p, int q) {
    LL ans = 0;
    for (int d = 17; d >= 0; d--) {
        if (q < (1 << d)) continue;
        ans += S[d][p];
        p = P[d][p];
        q -= (1 << d);
    }
    return ans;
}

int main() {
    cin >> N >> K;
    rep(i, N) cin >> A[i];

    deque<int> wnd;
    rep(i, N) {
        if (i >= K) P[0][i] = wnd.front();
        while (wnd.size()) { if (A[wnd.back()] < A[i]) break; wnd.pop_back(); }
        wnd.push_back(i);
        if (wnd.front() + K <= i) wnd.pop_front();
    }
    
    rep(d, 17) rep(i, N) P[d + 1][i] = P[d][P[d][i]];

    rep(i, N) S[0][i] = A[i];
    rep(d, 17) rep(i, N) S[d + 1][i] = S[d][i] + S[d][P[d][i]];

    LL ans = 1000000000000000000;
    for (int i = 1; i * K <= N; i++) ans = min(ans, getsum(i * K - 1, i));
    cout << ans << endl;

    return 0;
}
0