제출 #837958

#제출 시각아이디문제언어결과실행 시간메모리
837958MODDIBigger segments (IZhO19_segments)C++14
0 / 100
2 ms1236 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 dp[501][501]; int main(){ int n; cin>>n; vi arr(n); for(int i = 0; i < n; i++) cin>>arr[i]; int 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--){ if(j==0) dp[i][j] = 1; else{ for(int k = j - 1; k >= 0; k--){ ll r = pref[i] - pref[j-1]; ll l = pref[j-1]; if(k) l -= pref[k-1]; if(l <= r){ dp[i][j] = max(dp[i][j], dp[j-1][k] + 1); } } } } } 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...