# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
488146 | 2021-11-18T03:12:00 Z | ntabc05101 | Split the sequence (APIO14_sequence) | C++14 | 33 ms | 10492 KB |
#include<bits/stdc++.h> using namespace std; #define taskname "" const long long inf = 1e17; int main() { if (fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } else { if (fopen(taskname".in", "r")) { freopen(taskname".in", "r", stdin); freopen(taskname".out", "w", stdout); } } cin.tie(0)->sync_with_stdio(0); int n, K; cin >> n >> K; long long a[n + 1]; a[0] = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] += a[i - 1]; } vector<long long> dp[n + 1]; function<long double(int, int, int)> slope = [&](int k, int i, int j) { return (long double)(dp[i][k] - a[i] * a[i] - dp[j][k] + a[j] * a[j]) / (a[j] - a[i]); }; K++; int prf[n + 1][K + 1]; memset(prf, 0, sizeof(prf)); long long res = 0; for (int i = 0; i <= n; i++) { dp[i].assign(K + 1, -inf); } dp[0][0] = 0; deque<int> deq; for (int k = 1; k <= K; k++) { deq.clear(); deq.push_back(0); for (int i = 1; i <= n; i++) { while (deq.size() > 1 && slope(k - 1, deq[0], deq[1]) < a[i]) { deq.pop_front(); } int j = deq.front(); dp[i][k] = dp[j][k - 1] + (a[i] - a[j]) * a[j]; prf[i][k] = j; while (deq.size() > 1 && slope(k - 1, deq[deq.size() - 2], deq.back()) > slope(k - 1, deq.back(), i)) { deq.pop_back(); } deq.push_back(i); } } cout << dp[n][K] << "\n"; while (K > 1) { cout << prf[n][K] << " "; n = prf[n][K--]; } cout << "\n"; return 0; } /* 7 3 4 1 3 4 0 2 3 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | contestant found the optimal answer: 108 == 108 |
2 | Correct | 0 ms | 204 KB | contestant found the optimal answer: 999 == 999 |
3 | Correct | 0 ms | 204 KB | contestant found the optimal answer: 0 == 0 |
4 | Correct | 0 ms | 204 KB | contestant found the optimal answer: 1542524 == 1542524 |
5 | Correct | 0 ms | 204 KB | contestant found the optimal answer: 4500000000 == 4500000000 |
6 | Incorrect | 0 ms | 204 KB | contestant didn't find the optimal answer: 0 < 1 |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 204 KB | contestant didn't find the optimal answer: 252308 < 1093956 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 332 KB | contestant didn't find the optimal answer: 484133 < 610590000 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 332 KB | contestant didn't find the optimal answer: 395622 < 21503404 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1228 KB | contestant didn't find the optimal answer: 1187850 < 1818678304 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 33 ms | 10492 KB | contestant didn't find the optimal answer: 5054352 < 19795776960 |
2 | Halted | 0 ms | 0 KB | - |