# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
376326 | joelau | Bigger segments (IZhO19_segments) | C++14 | 20 ms | 35564 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int N,dp[3001][3001];
long long A[500001];
int main() {
scanf("%d", &N);
A[0] = 0;
for (int i = 1; i <= N; ++i) {
scanf("%lld", &A[i]);
A[i] += A[i-1];
}
memset(dp,-1,sizeof(dp));
for (int i = 0; i < N; ++i) {
dp[i][0] = 1;
int n = 0;
for (int j = 1; j <= i; ++j) {
while (n < j && A[i+1] - A[j] < A[j] - A[n]) n++;
if (dp[j-1][n] == -1) dp[i][j] = -1;
else dp[i][j] = dp[j-1][n] + 1;
}
for (int j = i-1; j >= 0; --j) dp[i][j] = max(dp[i][j],dp[i][j+1]);
}
printf("%d", dp[N-1][N-1]);
return 0;
}
Compilation message (stderr)
# | 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... |