# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
399588 | fedoseevtimofey | Cigle (COI21_cigle) | C++14 | 1086 ms | 139584 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 <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <bitset>
#include <chrono>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n;
cin >> n;
vector <int> d(n);
for (int i = 0; i < n; ++i) cin >> d[i];
vector <ll> pref(n + 1);
for (int i = 0; i < n; ++i) {
pref[i + 1] = pref[i] + d[i];
}
vector <vector <pair <int, int>>> go(n);
for (int i = 0; i + 1 < n; ++i) {
int r = 0;
for (int l = 1; l <= i + 1; ++l) {
while (r <= n - i - 1 && pref[i + 1] - pref[i + 1 - l] > pref[i + r + 1] - pref[i + 1]) ++r;
if (pref[i + 1] - pref[i + 1 - l] == pref[i + r + 1] - pref[i + 1]) {
go[i].push_back({l, r});
}
}
}
vector <vector <int>> dp(n + 1, vector <int> (n + 1));
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
int uk = 0;
for (int k = 1; k + i <= n; ++k) {
while (uk < go[i - 1].size() && j > go[i - 1][uk].first && k > go[i - 1][uk].second) ++uk;
dp[i + k][k] = max(dp[i + k][k], dp[i][j] + uk);
}
}
}
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';
}
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... |