結果

問題 No.1248 Kth Sum
ユーザー 👑 NachiaNachia
提出日時 2020-10-02 22:33:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,028 bytes
コンパイル時間 1,558 ms
コンパイル使用メモリ 170,364 KB
実行使用メモリ 47,444 KB
最終ジャッジ日時 2023-09-24 21:44:59
合計ジャッジ時間 6,009 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
44,324 KB
testcase_01 AC 10 ms
44,456 KB
testcase_02 AC 10 ms
44,304 KB
testcase_03 AC 10 ms
44,328 KB
testcase_04 AC 10 ms
44,336 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 9 ms
44,288 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
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,260 KB
testcase_24 WA -
testcase_25 AC 109 ms
47,100 KB
testcase_26 WA -
testcase_27 AC 98 ms
46,556 KB
testcase_28 AC 98 ms
46,580 KB
testcase_29 AC 109 ms
47,152 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 = K - 1; i < N; i++) ans = min(ans, getsum(i, i / K + 1));
    cout << ans << endl;

    return 0;
}
0