結果
| 問題 |
No.1117 数列分割
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-17 22:47:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,710 bytes |
| コンパイル時間 | 1,187 ms |
| コンパイル使用メモリ | 114,496 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-30 03:49:43 |
| 合計ジャッジ時間 | 11,148 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 WA * 21 |
ソースコード
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
constexpr Int INF = 1'000'000'000'000'000'000;
void segSet(int segN, vector<Int> &seg, int a, Int val) {
seg[a += segN] = val;
for (; a >>= 1; ) {
seg[a] = max(seg[a << 1], seg[a << 1 | 1]);
}
}
Int segGet(int segN, const vector<Int> &seg, int a, int b) {
Int ret = -INF;
for (a += segN, b += segN; a < b; a >>= 1, b >>= 1) {
if (a & 1) chmax(ret, seg[a++]);
if (b & 1) chmax(ret, seg[--b]);
}
return ret;
}
int N, K, M;
vector<Int> A;
int main() {
for (; ~scanf("%d%d%d", &N, &K, &M); ) {
A.resize(N);
for (int i = 0; i < N; ++i) {
scanf("%lld", &A[i]);
}
vector<Int> ASum(N + 1);
ASum[0] = 0;
for (int i = 0; i < N; ++i) {
ASum[i + 1] = ASum[i] + A[i];
}
vector<pair<Int, int>> ps(N + 1);
for (int i = 0; i <= N; ++i) {
ps[i] = {ASum[i], i};
}
sort(ps.begin(), ps.end());
vector<int> qs(N + 1);
for (int j = 0; j <= N; ++j) {
qs[ps[j].second] = j;
}
int segN;
for (segN = 1; segN < N + 1; segN <<= 1) {}
vector<Int> seg0(segN << 1, -INF);
vector<Int> seg1(segN << 1, -INF);
vector<Int> crt(N + 1, -INF);
crt[0] = 0;
for (int k = 0; k < K; ++k) {
vector<Int> nxt(N + 1, -INF);
for (int i = k + 1; i <= N; ++i) {
segSet(segN, seg0, qs[i - 1], crt[i - 1] - ASum[i - 1]);
segSet(segN, seg1, qs[i - 1], crt[i - 1] + ASum[i - 1]);
chmax(nxt[i], segGet(segN, seg0, 0, qs[i]) + ASum[i]);
chmax(nxt[i], segGet(segN, seg1, qs[i] + 1, N + 1) - ASum[i]);
if (i >= M) {
segSet(segN, seg0, qs[i - M], -INF);
segSet(segN, seg1, qs[i - M], -INF);
}
}
// cerr<<k+1<<": ";pv(nxt.begin(),nxt.end());
crt = nxt;
}
printf("%lld\n", crt[N]);
}
return 0;
}