Submission #964216

#TimeUsernameProblemLanguageResultExecution timeMemory
964216dubabubaSplit the sequence (APIO14_sequence)C++14
11 / 100
96 ms756 KiB
#include <bits/stdc++.h> using namespace std; template<typename T> void ono_max(T &MAX, T CMP) { if(MAX < CMP) MAX = CMP; } #define int long long const int mxk = 22; const int mxn = 1010; const int gay = 1e18; int dp[mxn][mxk], a[mxn], n; int ls[mxn][mxk], p[mxn], k; int kv(int a) { return a * a; } signed main() { cin >> n >> k; if(n > mxn) return 1; for(int i = 1; i <= n; i++) { cin >> a[i]; p[i] = p[i - 1] + a[i]; } for(int i = 1; i <= n; i++) for(int j = 0; j <= k; j++) { dp[i][j] = gay; if(j == 0) dp[i][j] = p[i] * p[i]; } // for(int cur = 2; cur <= n; cur++) // for(int las = 1; las < cur; las++) { // int las_sum = p[cur] - p[las]; // for(int j = 0; j < k && dp[las][j] != gay; j++) { // int CMP = dp[las][j] + las_sum * las_sum; // if(dp[cur][j + 1] == gay || dp[cur][j + 1] >= CMP) { // dp[cur][j + 1] = CMP; // ls[cur][j + 1] = las; // } // } // } for(int i = 2; i <= n; i++) for(int j = 1; j <= k; j++) for(int t = 1; t < i; t++) { if(dp[i][j] > dp[t][j - 1] + kv(p[i] - p[t])) { dp[i][j] = dp[t][j - 1] + kv(p[i] - p[t]); ls[i][j] = t; } } int t = (p[n] * p[n] - dp[n][k]) / 2; cout << t << endl; for(int i = k; i >= 0; i--) { n = ls[n][i]; if(n > 0) cout << n << ' '; } return 0; }
#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...