Codeforces 1363B. Subsequence Hate Solution
Solution in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- int main()
- {
- int t;
- cin >> t;
- while(t--)
- {
- string s;
- cin >> s;
- int z,o,z1,o1,ans=1e9,n,i,j;
- n=s.size();
- z=o=z1=o1=0;
- z=count(s.begin(),s.end(),'0');
- o=n-z;
- z1=z;
- o1=o;
- for(i=0; i<n; i++)
- {
- ans=min(ans,min(z1,o1));
- if(s[i]=='0')z1--,o1++;
- else
- o1--,z1++;
- }
- cout<<ans<<endl;
- }
- }
No comments