Submission #155650

#TimeUsernameProblemLanguageResultExecution timeMemory
155650HellAngelSplit the sequence (APIO14_sequence)C++14
33 / 100
162 ms131076 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int maxn = 1e5 + 7; int n, k, dp[207][maxn], a[maxn], m, prv[207][maxn]; void Solve(int x) { int cur = x - 1; for(int i = x; i <= n; i++) { while(cur + 1 < i && dp[x - 1][cur] + (a[i] - a[cur]) * a[cur] <= dp[x - 1][cur + 1] + (a[i] - a[cur + 1]) * a[cur + 1]) { cur++; } dp[x][i] = dp[x - 1][cur] + (a[i] - a[cur]) * a[cur]; prv[x][i] = cur; } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout); cin >> n >> m; for(int i = 1; i <= n; i++) { cin >> a[i]; a[i] += a[i - 1]; } for(int j = 2; j <= m + 1; j++) { Solve(j); } cout << dp[m + 1][n] << '\n'; vector<int> ans; for(int i = m; i >= 1; i--) { ans.push_back(prv[i + 1][n]); n = prv[i + 1][n]; } sort(ans.begin(), ans.end()); for(auto i: ans) cout << i << ' '; }

Compilation message (stderr)

sequence.cpp: In function 'int32_t main()':
sequence.cpp:26:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:26:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
#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...