Submission #910979

#TimeUsernameProblemLanguageResultExecution timeMemory
910979daoquanglinh2007Bigger segments (IZhO19_segments)C++17
27 / 100
1519 ms39596 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int NM = 3000, inf = 1e9+7; int n, a[NM+5], pref[NM+5], dp[NM+5][NM+5], ans = 0; signed main(){ //freopen("SEGMENTS.inp", "r", stdin); //freopen("SEGMENTS.ans", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i]; pref[i] = pref[i-1]+a[i]; } for (int j = 1; j <= n; j++) for (int i = 1; i <= j; i++){ dp[i][j] = (i == 1 ? 1 : -inf); for (int k = 1; k <= i-1; k++) if (pref[j]-pref[i-1] >= pref[i-1]-pref[k-1]) dp[i][j] = max(dp[i][j], dp[k][i-1]+1); if (j == n) ans = max(ans, dp[i][j]); } cout << 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...