Submission #685096

#TimeUsernameProblemLanguageResultExecution timeMemory
685096dostigatorBigger segments (IZhO19_segments)C++17
0 / 100
2 ms4308 KiB
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(),a.end()
#define pb push_back
#define vt vector
#define endl '\n'
#define Y second
#define X first
typedef long long ll;
typedef long double ld;
const ll mod=1e9+7;
const ll INF=1e18;
const int inf=1e9;
const int N=2e5+505;
const int M=1e3+10;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

/*From Benq:
    stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
        * DON'T GET STUCK ON ONE APPROACH*/

int n,a[N],dp[M][M];
ll pref[N];

ll sum(int l,int r){
	if(r==0)return 0;
	return pref[r]-pref[l-1];
}

void solve(){
	cin>>n;
	for(int i=0; i<M; ++i)for(int j=0; j<M; ++j)dp[i][j]=-1;
	for(int i=1; i<=n; ++i){
		cin>>a[i];
		pref[i]=pref[i-1]+a[i];
	}dp[0][0]=0;
	int res=0;
	for(int i=1; i<=n; ++i){
		dp[i][1]=1;
		for(int ans=2; ans<=i; ++ans){
			int l=0,r=i-1,ok=0;
			l=ans-1;
//			if(ans==1)ok=1;
			while(l<=r){
				int mid=(l+r)>>1;
				if(dp[mid][ans-1]==-1){
					l=mid+1;
					continue;
				}
				//if(i==5 && ans==3)cout<<mid<<endl;
		//		if(mid==4 && ans==3) cout<<dp[mid][ans-1]<<endl;
				if(dp[mid][ans-1]!=-1 && sum(dp[mid][ans-1],mid)<=sum(mid+1,i)){
					l=mid+1;
					ok=1;
					//cout<<mid+1<<' '<<"yes\n";
				}
				else r=mid-1;
			}dp[i][ans]=l;
			if(!ok)dp[i][ans]=-1;
			//cout<<l<<' '<<r<<endl;
		//	cout<<i<<' '<<ans<<' '<<dp[i][ans]<<endl;
			if(l>0 && ok)res=max(res,ans);
		}
	}cout<<res<<endl;
}

int main(){
	//srand(time(0));
	//freopen("hotel.in","r",stdin);
	//freopen("hotel.out","w",stdout);
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int tt=1,lolol=0;
//	cin>>tt;
	while(tt--) {
		//cout<<"Case "<<++lolol<<": ";
		solve();
	}
}

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:79:11: warning: unused variable 'lolol' [-Wunused-variable]
   79 |  int tt=1,lolol=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...