Submission #915408

#TimeUsernameProblemLanguageResultExecution timeMemory
915408PekibanSplit the sequence (APIO14_sequence)C++17
0 / 100
12 ms4696 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = 1e5+2, mxK = 202; int to[mxK][mxN]; long long pref[mxN], dpb[mxN], dp[mxN], c, t; long double cord(int x, int y) { return (long double)(dpb[y] - pref[y]*pref[y] + pref[x]*pref[x] - dpb[x])/(pref[x] - pref[y]); // deljenje 0-om? } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; for (int i = 1; i <= n; ++i) { int x; cin >> x; pref[t] = pref[t-1] + x; } for (int i = 1; i <= k; ++i) { deque<int> dq = {0}; for (int j = 1; j <= n; ++j) { while (dq.size() > 1 && cord(dq[0], dq[1]) <= pref[j]) dq.pop_front(); dp[j] = pref[j]*pref[dq[0]] + dpb[dq[0]] - pref[dq[0]]*pref[dq[0]]; to[i][j] = dq[0]; while (dq.size() > 1 && cord(dq[dq.size()-1], dq[dq.size()-2]) >= cord(dq[dq.size()-2], j)) dq.pop_back(); dq.push_back(j); } for (int i = 1; i <= n; ++i) { dpb[i] = dp[i]; } ++c; } cout << dp[n] << '\n'; int idx = to[k][n]; for (int i = k; i >= 1; --i) { cout << idx << ' '; idx = to[k][idx]; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...