Submission #155646

#TimeUsernameProblemLanguageResultExecution timeMemory
155646HellAngelSplit the sequence (APIO14_sequence)C++14
0 / 100
15 ms3640 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; 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]; } } 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]; }

Compilation message (stderr)

sequence.cpp: In function 'int32_t main()':
sequence.cpp:25: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:25: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...