| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1327207 | Double_Slash | 수열 (APIO14_sequence) | C++20 | 600 ms | 83444 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
struct Line {
int a;
ll b;
ll operator()(int x) const { return (ll) a * x + b; }
Line operator-(const Line &o) const { return {a - o.a, b - o.b}; }
ll operator*(const Line &o) const { return a * o.b - o.a * b; }
};
struct CHT : deque<Line> {
void add(const Line &o) {
while (size() >= 2 and (back() - end()[-2]) * (o - end()[-2]) >= 0) pop_back();
push_back(o);
}
ll query(int x) {
while (size() >= 2 and front()(x) > begin()[1](x)) pop_front();
return front()(x);
}
};
int n, k, a[100000], dp[100000][201];
ll ps[100001];
int main() {
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i];
ps[i] = (i ? ps[i - 1] : 0) + a[i];
}
vector<ll> cur(n, INF);
for (int j = 0; j <= k; ++j) {
vector<ll> nxt(n);
CHT cht;
cht.add({0, 0});
for (int i = 0; i < n; ++i) {
dp[i][j] = (nxt[i] = ps[i] * ps[i] + cht.query(ps[i])) % INT32_MAX;
if (a[i]) cht.add({-2 * ps[i], ps[i] * ps[i] + cur[i]});
}
cur = move(nxt);
}
ll ans = cur.back();
cout << (ps[n - 1] * ps[n - 1] - ans) / 2 << endl;
ll ps = 0;
for (int i = n; k;) {
ps += a[--i];
if ((dp[i - 1][k - 1] + ps * ps) % INT32_MAX == ans % INT32_MAX) {
ans -= ps * ps;
k--;
ps = 0;
cout << i << " ";
}
}
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
