제출 #34090

#제출 시각아이디문제언어결과실행 시간메모리
34090DoanPhuDuc수열 (APIO14_sequence)C++98
100 / 100
1659 ms86788 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; const int INF = 2e9 + 10; int n, m, ansSize = 0; int a[N], ans[N]; int S[N]; int tr[M][N]; LL dp[2][N]; void Compute(int p, int l, int r, int u, int v) { if (l > r) return; int m = (l + r) >> 1; int nxt = p & 1, pre = nxt ^ 1; if (p < m) { int x = max(u, p), y = min(m - 1, v), best = -1; FOR(i, x, y) if (dp[nxt][m] < dp[pre][i] + (LL)S[i] * (S[m] - S[i])) { dp[nxt][m] = dp[pre][i] + (LL)S[i] * (S[m] - S[i]); tr[p][m] = 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, n) dp[0][i] = 0; FOR(i, 1, m) { FOR(j, 0, n) dp[i & 1][j] = -INF; Compute(i, 1, n, 1, n); } printf("%lld\n", dp[m & 1][n]); while (tr[m][n] != 0) { ans[++ansSize] = tr[m][n]; n = tr[m][n]; --m; } FOD(i, ansSize, 1) printf("%d ", ans[i]); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp: In function 'int main()':
sequence.cpp:52: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:53: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...