제출 #34082

#제출 시각아이디문제언어결과실행 시간메모리
34082DoanPhuDuc수열 (APIO14_sequence)C++98
0 / 100
0 ms1840 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 tr[M][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; 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]); tr[p][m] = i; best = i; } Compute(p, l, m - 1, u, best); Compute(p, m + 1, r, best, 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); } printf("%lld\n", dp[m][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:50:30: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
     printf("%lld\n", dp[m][n]);
                              ^
sequence.cpp:44: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:45: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...