# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
376296 | Halogen | Bigger segments (IZhO19_segments) | C++14 | 145 ms | 262144 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;
#define int long long
int N, presum[500005];
int memo[505][505][505];
int dp(int x, int y, int z) {
if (memo[x][y][z] != -1) return memo[x][y][z];
int ans = 0, preseg = presum[z - 1] - presum[y], curseg = presum[x - 1] - presum[y];
if (x >= N) {
if (curseg - preseg + presum[x] - presum[x - 1] >= 0) ans = 0;
else ans = -10234567898765432;
}
else if (curseg - preseg < 0) ans = dp(x + 1, y, z);
else ans = max(
dp(x + 1, y, z),
1 + dp(x + 1, x, z)
);
// printf("%lld %lld %lld\n", ans, x, seg);
return memo[x][y][z] = ans;
}
main() {
scanf("%lld", &N);
memset(memo, -1, sizeof(memo));
for (int i = 1; i <= N; i++) scanf("%lld", &presum[i]);
for (int i = 2; i <= N; i++) presum[i] += presum[i - 1];
printf("%lld\n", dp(1, 0, 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... |