제출 #265458

#제출 시각아이디문제언어결과실행 시간메모리
265458square1001수열 (APIO14_sequence)C++14
50 / 100
2084 ms24832 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]) * (S[i] - S[k])) { dp[i][j] = dp[k][j - 1] + 1LL * (S[i] - S[k]) * (S[i] - S[k]); pre[i][j] = k; } } } } cout << (1LL * S[N] * S[N] - dp[N][K]) / 2 << 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...