Submission #669837

#TimeUsernameProblemLanguageResultExecution timeMemory
669837CyanmondCigle (COI21_cigle)C++17
100 / 100
442 ms98712 KiB
#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; { 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]); } } } const int m = (int)points.size(); 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, count_p = 0; for (int i = 1; i < t; ++i) { // dp[s + i][s] while (count_p != m and points[count_p] <= a[i - 1]) { while (r != s - 1 and b[r] < points[count_p]) { max_v = std::max(max_v, dp[s - 1][s - r - 2] + count_p); ++r; } ++count_p; } dp[s + i][s] = std::max(max_v, r == s - 1 ? 0 : (max_c[s - r - 2] + count_p)); /* 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...