結果
| 問題 | No.1248 Kth Sum |
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2020-10-02 22:33:33 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,028 bytes |
| 記録 | |
| コンパイル時間 | 1,622 ms |
| コンパイル使用メモリ | 172,260 KB |
| 実行使用メモリ | 47,412 KB |
| 最終ジャッジ日時 | 2024-07-17 22:08:35 |
| 合計ジャッジ時間 | 5,794 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 WA * 27 |
ソースコード
#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;
}
Nachia