Advertisement
ec1117

Untitled

Feb 20th, 2022
1,024
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     // freopen("socdist1.in","r",stdin);
  7.     // freopen("socdist1.out","w",stdout);
  8.  
  9.     int n;cin>>n;
  10.     string S;cin>>S;
  11.     vector<int> v;
  12.    
  13.     int lst=-1, D=1e9;
  14.     int L=0,R=0;
  15.     bool none=true;
  16.     for(int i=0;i<n;i++){
  17.         if(S[i]=='1'){
  18.             none=false;
  19.             if(lst!=-1)v.push_back(i-lst);
  20.             else L=i+1;
  21.             D=max(D,i-lst);
  22.             lst=i;
  23.         }
  24.     }
  25.     R=n-lst;
  26.     // cout<<L<<" "<<R<<endl;
  27.  
  28.     sort(v.begin(),v.end());
  29.     // for(int x:v)cout<<x<<endl;
  30.  
  31.     if(none){
  32.         cout<<n-1<<endl;
  33.         exit(0);
  34.     }
  35.    
  36.     int b1=0;
  37.     int b2=0;
  38.     if(v.size()>=1){
  39.         b1=v.back()/3;
  40.     }
  41.     if(v.size()>=2){
  42.         int mx=v.back();
  43.         int mx2=v[v.size()-2];
  44.         b2=min(mx/2,mx2/2);
  45.     }
  46.     // cout<<b1<<b2<<endl;
  47.  
  48.     int mx=max(b1,b2);
  49.     mx=max(mx,min(L-1,R-1));
  50.  
  51.     int side=max(L-1,R-1);
  52.     if(v.size()>=1){
  53.         mx=max(mx,min(side,v.back()/2));
  54.     }
  55.  
  56.     mx=max(mx, L/2);
  57.     mx=max(mx, R/2);
  58.  
  59.     cout<<mx<<endl;
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement