Submission #159066

#TimeUsernameProblemLanguageResultExecution timeMemory
159066mrboorgerBigger segments (IZhO19_segments)C++17
37 / 100
119 ms57848 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> //#include "interactive.h" #define pb push_back #define F first #define S second #define ll long long #define ld long double #define sqr(x) (x) * (x) //#define all(a) a.begin(), a.end() using namespace std; const int maxn = 3005; const int inf = 10000000; int dp[maxn][maxn]; int a[maxn]; ll sum[maxn]; ll f(int l, int r) { return sum[r] - sum[l - 1]; } int main() { #ifdef LOCAL // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif // LOCAL // ios_base::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); int n; cin >> n; for(int i = 0; i < n; ++i) { cin >> a[i]; sum[i + 1] = a[i] + sum[i]; } for(int i = 0; i <= n; ++i) for(int j = 0; j <= i + 1; ++j) dp[i][j] = inf; dp[0][0] = 0; dp[1][1] = 1; for(int i = 1; i < n; ++i) for(int j = 0; j <= i + 1; ++j) { if (dp[i][j] == inf) continue; dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1); { ll q = f(i - dp[i][j] + 1, i); int l = i + 1, r = n; int b = inf; while(l <= r) { int m = (l + r) / 2; if (f(i + 1, m) >= q) { b = min(b, m); r = m - 1; } else { l = m + 1; } } if (b < inf) { dp[b][j + 1] = min(dp[b][j + 1], b - i); } } } int ans = 0; for(int j = 1; j <= n; ++j) if (dp[n][j] != inf) ans = max(ans, j); cout << ans << endl; return 0; }
#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...