Submission #1153211

#TimeUsernameProblemLanguageResultExecution timeMemory
1153211asdasdBigger segments (IZhO19_segments)C++20
0 / 100
0 ms328 KiB
//gm --- akezhon #include <bits/stdc++.h> // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define pb push_back #define pf push_front #define F first #define S second #define all(v) v.begin(),v.end() #define pii pair<int,int> #define tm (tl+tr)/2 #define TL v+v, tl, tm #define TR v+v+1, tm+1, tr #define DA l <= tl && tr <= r #define NE r < tl || tr < l #define int long long using namespace std; const int N=5e5+7; const int mod=998244353; const int inf=2e18; int dp[N]; int sm[N]; int a[N]; int p[N]; int n; void AlemAmenov(){ cin >> n; for(int i=1; i<=n; i++){ cin >> a[i]; p[i] = p[i-1] + a[i]; sm[i]=inf; } for(int i=1; i <= n; i++){ int last=dp[i-1]; for(int j=i-1; j >= 0; j--){ if(dp[i] < dp[j] || (dp[i]==dp[j] && sm[j]+p[i]-p[j] < sm[i])){ dp[i]=dp[j]; sm[i]=sm[j]+p[i]-p[j]; } if(sm[j] <= p[i]-p[j] && (dp[i] < dp[j]+1 || (dp[i]==dp[j]+1 && p[i]-p[j] < sm[i])) ){ dp[i]=dp[j]+1; sm[i]=p[i]-p[j]; } if(dp[j] != last)break; } } cout << dp[n]; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int RealName=1; // cin >> RealName; // srand(time(0)); while(RealName--) AlemAmenov(); 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...