Submission #977093

#TimeUsernameProblemLanguageResultExecution timeMemory
977093AmaarsaaSplit the sequence (APIO14_sequence)C++14
50 / 100
2053 ms32092 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long ; int main() { // freopen("moocast.in", "r", stdin); // freopen("moocast.out", "w", stdout); ios::sync_with_stdio(false); cin.tie(NULL); ll t, n, m, ans, s, mx, mx_cnt, x, y, r, p, i, j; cin >> n >> m; ll a[n + 2], dp[m + 2][n + 2], sum[n + 2]; sum[0] = 0; for (i = 1; i <= n; i ++) { cin >> a[i]; sum[i] = sum[i - 1] + a[i]; } dp[0][0] = 0; ll Comes[m +2][n + 2]; for (i = 1; i <= n; i ++) dp[1][i] = sum[i] * (sum[n] - sum[i]), Comes[1][i] = 0; for (i = 2; i <= m + 1; i ++) { for (j = 1; j <= n; j ++) { Comes[i][j] = 0; dp[i][j] = 0; for ( r = 1; r < j; r ++) { if ( dp[i][j] <= dp[i - 1][r] + (sum[j] - sum[r]) * (sum[n] - sum[j])) { Comes[i][j] = r; dp[i][j] = dp[i - 1][r] + (sum[j] - sum[r]) * (sum[n] - sum[j]); } } } } vector < ll > v; cout << dp[m + 1][n] << endl; i = m + 1; j = n; while (j != 0) { v.push_back(j); j = Comes[i][j]; i --; } reverse(v.begin(), v.end()); v.pop_back(); for ( ll X : v) cout << X << " "; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:10:5: warning: unused variable 't' [-Wunused-variable]
   10 |  ll t, n, m, ans, s, mx, mx_cnt, x, y, r, p, i, j;
      |     ^
sequence.cpp:10:14: warning: unused variable 'ans' [-Wunused-variable]
   10 |  ll t, n, m, ans, s, mx, mx_cnt, x, y, r, p, i, j;
      |              ^~~
sequence.cpp:10:19: warning: unused variable 's' [-Wunused-variable]
   10 |  ll t, n, m, ans, s, mx, mx_cnt, x, y, r, p, i, j;
      |                   ^
sequence.cpp:10:22: warning: unused variable 'mx' [-Wunused-variable]
   10 |  ll t, n, m, ans, s, mx, mx_cnt, x, y, r, p, i, j;
      |                      ^~
sequence.cpp:10:26: warning: unused variable 'mx_cnt' [-Wunused-variable]
   10 |  ll t, n, m, ans, s, mx, mx_cnt, x, y, r, p, i, j;
      |                          ^~~~~~
sequence.cpp:10:34: warning: unused variable 'x' [-Wunused-variable]
   10 |  ll t, n, m, ans, s, mx, mx_cnt, x, y, r, p, i, j;
      |                                  ^
sequence.cpp:10:37: warning: unused variable 'y' [-Wunused-variable]
   10 |  ll t, n, m, ans, s, mx, mx_cnt, x, y, r, p, i, j;
      |                                     ^
sequence.cpp:10:43: warning: unused variable 'p' [-Wunused-variable]
   10 |  ll t, n, m, ans, s, mx, mx_cnt, x, y, r, p, i, j;
      |                                           ^
#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...