이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
vector<int> d(n);
for (int &x : d) {
cin >> x;
}
vector<vector<int>> f(n, vector<int>(n));
for (int i = 0; i < n - 1; i++) {
vector<int> num(n);
int l = i, r = i + 1, s = 0, cnt = 0;
while (~l || r < n) {
if (r == n || s <= 0 && l >= 0) s += d[l--];
else s -= d[r++];
if (!s) cnt++;
if (~l) num[l] = cnt;
if (r < n) num[r] = cnt;
}
vector<int> pre(i + 1);
for (int j = 0; j <= i; j++) {
pre[j] = max(j ? pre[j - 1] : 0, f[j][i]);
}
for (int k = i + 1, j = i, t = 0; k < n; k++) {
for (; ~j && num[j] <= num[k]; j--) {
t = max(t, f[j][i] + num[j]);
}
f[i + 1][k] = max(t, ~j ? pre[j] + num[k] : 0);
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
ans = max(ans, f[i][n - 1]);
}
cout << ans << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
cigle.cpp: In function 'int main()':
cigle.cpp:17:34: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
17 | if (r == n || s <= 0 && l >= 0) s += d[l--];
| ~~~~~~~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |