Submission #265462

#TimeUsernameProblemLanguageResultExecution timeMemory
265462square1001Split the sequence (APIO14_sequence)C++14
50 / 100
2045 ms24960 KiB
// APIO 2014 Problem 2 - Split the Sequence #include <vector> #include <iostream> #include <algorithm> using namespace std; const long long inf = 1LL << 60; int main() { // step #1. read input int N, K; cin >> N >> K; ++K; vector<int> A(N); for(int i = 0; i < N; ++i) { cin >> A[i]; } // step #2. preparation for calculating the answer vector<int> S(N + 1); for(int i = 0; i < N; ++i) { S[i + 1] = S[i] + A[i]; } vector<vector<long long> > dp(N + 1, vector<long long>(K + 1, inf)); vector<vector<int> > pre(N + 1, vector<int>(K + 1, -1)); dp[0][0] = 0; for(int i = 1; i <= N; ++i) { for(int j = 1; j <= K; ++j) { for(int k = 0; k < i; ++k) { if(dp[i][j] > dp[k][j - 1] - 1LL * S[i] * S[k]) { dp[i][j] = dp[k][j - 1] - 1LL * S[i] * S[k]; pre[i][j] = k; } } dp[i][j] += 1LL * S[i] * S[i]; } } cout << 1LL * S[N] * S[N] - dp[N][K] << endl; int pos = N; for(int i = K; i >= 2; --i) { cout << pre[pos][i] << (i != 2 ? ' ' : '\n'); pos = pre[pos][i]; } 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...