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>
int main() {
int N;
std::cin >> N;
std::vector<int> D(N);
for (auto &e : D) {
std::cin >> e;
}
std::vector<std::vector<int>> dp(N, std::vector<int>(N));
for (int s = 1; s < N; ++s) {
std::vector<int> a, b;
for (int i = s; i < N; ++i) {
a.push_back(D[i]);
if (i != s) {
a[i - s] += a[i - s - 1];
}
}
for (int i = 0; i < s; ++i) {
b.push_back(D[s - i - 1]);
if (i != 0) {
b[i] += b[i - 1];
}
}
const int t = (int)a.size();
std::vector<int> points;
std::vector<bool> is_p_a(t), is_p_b(s);
{
int r = 0;
for (int i = 0; i < t - 1; ++i) {
while (r != s and b[r] < a[i]) {
++r;
}
if (r < s - 1 and a[i] == b[r]) {
points.push_back(a[i]);
is_p_a[i] = true;
is_p_b[r] = true;
}
}
}
const int m = (int)points.size();
std::vector<std::pair<int, int>> condition(m);
{
int r1 = 0, r2 = 0;
for (int i = 0; i < m; ++i) {
while (a[r1] < points[i]) {
++r1;
}
while (b[r2] < points[i]) {
++r2;
}
condition[i] = {r1, r2};
}
}
std::vector<int> max_c(s);
for (int i = 0; i < s; ++i) {
max_c[i] = dp[s - 1][i];
if (i != 0) {
max_c[i] = std::max(max_c[i], max_c[i - 1]);
}
}
int max_v = 0;
dp[s][s] = max_c[s - 1];
int r = 0;
for (int i = 1; i < t; ++i) {
// dp[s + i][s]
for (int j = 0; j < s - 1; ++j) {
int v = dp[s - 1][j];
auto itr = std::upper_bound(points.begin(), points.end(), std::min(a[i - 1], b[s - j - 2]));
dp[s + i][s] = std::max(dp[s + i][s], v + (int)(itr - points.begin()));
}
}
}
std::cout << *std::max_element(dp[N - 1].begin(), dp[N - 1].end()) << std::endl;
}
Compilation message (stderr)
cigle.cpp: In function 'int main()':
cigle.cpp:67:13: warning: unused variable 'max_v' [-Wunused-variable]
67 | int max_v = 0;
| ^~~~~
cigle.cpp:69:13: warning: unused variable 'r' [-Wunused-variable]
69 | int r = 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... |