Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define int long long
- #define inf 2e18
- int MOD=1000000007;//998244353;
- const int nn=1000050;
- bool prime[nn]; //array to store precalculated primes till 10^6
- void cal_primes(){memset(prime,true,sizeof(prime)); for(int i=2;i<=sqrt(nn);++i){ if(prime[i]==true){ for(int j=i*i;j<=nn;j+=i){prime[j]=false;}}}}
- void solve(int t)
- {
- int testcases=t;
- while(t--)
- {
- string s;cin>>s;
- int n=s.length(),ans=0,len=0,c0=0,c1=0;
- vector<pair<char,int>>v;
- for(int i=0;i<n;i++)
- {
- if(s[i]=='0')
- {
- if(c1>0)
- v.push_back(make_pair('1',c1)),c1=0;
- c0++;
- }
- else
- {
- if(c0>0)
- v.push_back(make_pair('0',c0)),c0=0;
- c1++;
- }
- }
- if(c1>0)
- v.push_back(make_pair('1',c1)),c1=0;
- else
- v.push_back(make_pair('0',c0)),c0=0;
- // for(auto it:v)
- // cout<<it.first<<" "<<it.second<<endl;
- for(int i=0;i<v.size();i++)
- {
- ans=0;
- if(v[i].first=='1')
- {
- ans+=v[i].second;
- if(i!=0)
- ans+=v[i-1].second;
- if(i!=(v.size()-1))
- ans+=v[i+1].second;
- }
- else
- ans+=v[i].second;
- len=max(len,ans);
- }
- cout<<len<<endl;
- }
- }
- main()
- {
- auto start=chrono::system_clock::now();
- {
- #ifndef ONLINE_JUDGE
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- freopen("error.txt","w",stderr);
- #endif
- ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- int t=1;
- // cin>>t;
- solve(t);
- }
- auto end=chrono::system_clock::now();
- chrono::duration<double> elapsed=end-start;
- // cout<<endl<<"Time taken: "<<elapsed.count()<<" sec";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement