이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define y1 theboatman
#define make_struct(args...) {args}
using namespace std;
typedef long long ll;
const long long INF = 1e18 + 10;
const int inf = 1e9 + 10;
const int N = 1e6 + 10;
int dp[3000][3000];
vector <ll> pref;
ll get(int l, int r) {
ll res = pref[r];
return (l ? res - pref[l - 1] : res);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
vector <int> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
dp[i][j] = -inf;
}
}
for(int i = 0; i < n; i++) {
dp[0][i] = 1;
}
pref.resize(n);
for(int i = 0; i < n; i++) {
pref[i] = (i ? pref[i - 1] + a[i] : a[i]);
}
vector <int> line(n + 1, -inf);
for(int i = 0; i < n; i++) {
for(int j = i; j < n; j++) {
int l = j + 1, r = n;
while(l < r) {
int c = (l + r) / 2;
if (get(i, j) > get(j + 1, c)) {
l = c + 1;
}
else {
r = c;
}
}
dp[i][j] = max(dp[i][j], line[j]);
line[l] = max(line[l], dp[i][j] + 1);
line[j + 1] = max(line[j], line[j + 1]);
}
}
int ans = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
ans = max(ans, dp[i][j]);
}
}
cout << ans << "\n";
return 0;
}
/*
*/
# | 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... |