Submission #416245

#TimeUsernameProblemLanguageResultExecution timeMemory
416245DEQKSplit the sequence (APIO14_sequence)C++17
100 / 100
1062 ms80944 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 100100; int n, k; ll a[N]; ll dp[N][2]; int p[201][N]; int cur; void solve(int l,int r,int tl,int tr) { if(l > r) return; int m = l + r >> 1; for(int i = tl; i < min(m, tr + 1); i++) { if(dp[m][1] <= dp[i][0] + a[i] * (a[m] - a[i])) { dp[m][1] = dp[i][0] + a[i] * (a[m] - a[i]); p[cur][m] = i; } } solve(l, m - 1, tl, p[cur][m]); solve(m + 1, r, p[cur][m], tr); } int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> k; for(int i = 1; i <= n; ++i) { cin >> a[i]; a[i] += a[i - 1]; } for(int j = 1; j <= k; j++) { cur = j; solve(1, n, 1, n); for(int i = 1; i <= n; i++) { dp[i][0] = dp[i][1]; dp[i][1] = 0; } } cout << dp[n][0] << "\n"; int pos = n; for(int j = k; j; j--) { cout << p[j][pos] << " "; pos = p[j][pos]; } }

Compilation message (stderr)

sequence.cpp: In function 'void solve(int, int, int, int)':
sequence.cpp:13:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 |  int m = l + r >> 1;
      |          ~~^~~
#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...