Submission #181000

#TimeUsernameProblemLanguageResultExecution timeMemory
181000BTheroBigger segments (IZhO19_segments)C++17
27 / 100
1547 ms71032 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define sz(x) (int)(x).size() #define S second #define F first #define all(x) (x).begin(), (x).end() using namespace std; const bool dbg_flg = 1; #define debug(x) if (dbg_flg) cerr << #x << ' ' << x << '\n' #define debug_pair(x) if (dbg_flg) cerr << #x << ' ' << x.F << ' ' << x.S << '\n' const int inf = 1e9 + 7; const int MAXN = 3000 + 5; int n; ll a[MAXN]; ll pref[MAXN]; ll dp[MAXN][MAXN]; int main() { //~ freopen(".in", "r", stdin); //~ freopen(".out", "w", stdout); ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; pref[i] = pref[i - 1] + a[i]; } for (int i = 0; i <= n; ++i) { for (int j = 0; j <= n; ++j) { dp[i][j] = (ll)1e18; } } dp[0][0] = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= i; ++j) { for (int L = 1; L <= i; ++L) { if (dp[L - 1][j - 1] <= pref[i] - pref[L - 1]) { dp[i][j] = min(dp[i][j], pref[i] - pref[L - 1]); } } } } ll ans = 0; while (ans < n && dp[n][ans + 1] != (ll)1e18) { ++ans; } printf("%lld\n", ans); 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...