Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- int main(){
- // freopen("socdist1.in","r",stdin);
- // freopen("socdist1.out","w",stdout);
- int n;cin>>n;
- string S;cin>>S;
- vector<int> v;
- int lst=-1, D=1e9;
- int L=0,R=0;
- bool none=true;
- for(int i=0;i<n;i++){
- if(S[i]=='1'){
- none=false;
- if(lst!=-1)v.push_back(i-lst);
- else L=i+1;
- D=max(D,i-lst);
- lst=i;
- }
- }
- R=n-lst;
- // cout<<L<<" "<<R<<endl;
- sort(v.begin(),v.end());
- // for(int x:v)cout<<x<<endl;
- if(none){
- cout<<n-1<<endl;
- exit(0);
- }
- int b1=0;
- int b2=0;
- if(v.size()>=1){
- b1=v.back()/3;
- }
- if(v.size()>=2){
- int mx=v.back();
- int mx2=v[v.size()-2];
- b2=min(mx/2,mx2/2);
- }
- // cout<<b1<<b2<<endl;
- int mx=max(b1,b2);
- mx=max(mx,min(L-1,R-1));
- int side=max(L-1,R-1);
- if(v.size()>=1){
- mx=max(mx,min(side,v.back()/2));
- }
- mx=max(mx, L/2);
- mx=max(mx, R/2);
- cout<<mx<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement