Submission #762545

#TimeUsernameProblemLanguageResultExecution timeMemory
762545MODDIBigger segments (IZhO19_segments)C++14
0 / 100
14 ms35524 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair typedef long long ll; typedef pair<long long, long long> pll; typedef pair<int,int> pii; typedef vector<long long> vl; typedef vector<int> vi; int n; vi arr; int dp[3001][3001]; // maximum number of segments if we are at the ith position and the last segment begun at j int main(){ cin>>n; arr.resize(n); for(int i = 0; i < n; i++) cin>>arr[i]; ll pref[n]; pref[0] = arr[0]; for(int i = 1; i < n; i++) pref[i] = pref[i-1] + arr[i]; memset(dp, 0, sizeof dp); dp[0][0] = 1; for(int i = 1; i < n; i++){ for(int j = i; j >= 0; j--){ for(int k = j - 1; k >= 0; k--){ ll sumL = pref[j-1], sumR = pref[i]; if(j > 0) sumR -= pref[j-1]; if(k > 0) sumL -= pref[k-1]; if(sumR >= sumL) dp[i][j] = max(dp[i][j], dp[j-1][k] + 1); // cout<<i<<" "<<j<<" "<<sumR<<endl; // cout<<j-1<<" "<<k<<" "<<sumL<<endl; // cout<<"DP: "<<dp[i][j]<<endl; } } } int ans = 0; for(int i = 0; i < n; i++){ ans = max(ans, dp[n-1][i]); } 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...