Submission #441553

#TimeUsernameProblemLanguageResultExecution timeMemory
441553leakedBigger segments (IZhO19_segments)C++14
27 / 100
1594 ms35660 KiB
#include <bits/stdc++.h> #define vec vector #define sz(x) (int)x.size() using namespace std; typedef long long ll; auto rng=bind(uniform_int_distribution<int>(1,1e6),mt19937(time(0))); template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);} template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);} int brute(vec<int> a){ int n=sz(a); vec<vec<int>>dp(n,vec<int>(n,-2*n)); vec<ll>pref(n,0); for(int i=0;i<n;i++) pref[i]=(i?pref[i-1]:0)+a[i]; auto get=[&](int l,int r){ return pref[r]-(l?pref[l-1]:0); }; int ans=0; for(int i=0;i<n;i++){ umax(dp[0][i],1); for(int j=0;j<=i;j++){ for(int k=i+1;k<n;k++){ if(get(i+1,k)>=get(j,i)){ umax(dp[i+1][k],dp[j][i]+1); } } // cout<<i<<' '<<j<<endl; umax(ans,dp[j][i]); } } return ans; } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n; cin>>n; vec<int>a(n); vec<ll>pref(n); for(auto &z : a) cin>>z; cout<<brute(a); return 0; for(int i=0;i<n;i++){ pref[i]=(i?pref[i-1]:0)+a[i]; } auto get=[&](int l,int r){ return pref[r]-pref[l-1]; }; ll lst=a[0],s=0; int cnt=1; int w=0; for(int i=1;i<n;i++){ s+=a[i]; if(s>=lst){ int j=w; while(1){ if(pref[i]-pref[j]<pref[j]-pref[w]+lst) break; j++; } j--; cnt++; lst=pref[i]-pref[j]; w=i; s=0; } } cout<<cnt; return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:47:10: warning: variable 'get' set but not used [-Wunused-but-set-variable]
   47 |     auto get=[&](int l,int r){
      |          ^~~
#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...