Submission #34084

#TimeUsernameProblemLanguageResultExecution timeMemory
34084DoanPhuDucSplit the sequence (APIO14_sequence)C++98
0 / 100
1289 ms85228 KiB
#include <bits/stdc++.h> #define FOR(x, a, b) for (int x = a; x <= b; ++x) #define FOD(x, a, b) for (int x = a; x >= b; --x) #define REP(x, a, b) for (int x = a; x < b; ++x) #define DEBUG(X) { cout << #X << " = " << X << endl; } #define PR(A, n) { cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl; } #define PR0(A, n) { cout << #A << " = "; REP(_, 0, n) cout << A[_] << " "; cout << endl; } #define BitCount(x) __builtin_popcount(x) using namespace std; typedef long long LL; const int N = 1e5 + 10; const int M = 2e2 + 10; int n, m, ansSize = 0; int a[N], ans[N]; int S[N]; int dp[M][N]; void Compute(int p, int l, int r, int u, int v) { if (l > r) return; int m = (l + r) >> 1; if (p < m) { int x = u, y = min(m - 1, v), best = -1; FOR(i, x, y) if (dp[p][m] < dp[p - 1][i] + S[i] * (S[m] - S[i])) { dp[p][m] = dp[p - 1][i] + S[i] * (S[m] - S[i]); best = i; } Compute(p, l, m - 1, u, best); Compute(p, m + 1, r, best, v); } else { Compute(p, l, m - 1, u, v); Compute(p, m + 1, r, u, v); } } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // LOCAL scanf("%d%d", &n, &m); FOR(i, 1, n) scanf("%d", &a[i]); FOR(i, 1, n) S[i] = S[i - 1] + a[i]; FOR(i, 1, m) { Compute(i, 1, n, 1, n); } /* memset(tr, -1, sizeof tr); FOR(i, 1, m) FOR(j, i + 1, n) FOR(k, i, j) if (dp[i][j] < dp[i - 1][k] + S[k] * (S[j] - S[k])) { dp[i][j] = dp[i - 1][k] + S[k] * (S[j] - S[k]); tr[i][j] = k; }*/ printf("%d\n", dp[m][n]); int j = n; FOD(i, m, 1) FOR(k, 1, j) if (dp[i - 1][k] + S[k] * (S[j] - S[k]) == dp[i][j]) { ans[++ansSize] = k; j = k; break; } FOD(i, ansSize, 1) printf("%d ", ans[i]); cout << endl; return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:47:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
                          ^
sequence.cpp:48:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     FOR(i, 1, n) scanf("%d", &a[i]);
                                    ^
#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...