Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize ("O3")
- #pragma GCC target ("sse4")
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> pii;
- typedef pair<string,int> psi;
- typedef unordered_map<int,int> mii;
- typedef unordered_map<long long,long long> mll;
- typedef unordered_map<string,int> msi;
- typedef unordered_map<char,int> mci;
- typedef unordered_set<int> si;
- typedef unordered_set<long long> sll;
- typedef unordered_set<string> ss;
- typedef unordered_set<char> sc;
- typedef map<int,int> ormii;
- typedef map<long long,long long> ormll;
- typedef map<string,int> ormsi;
- typedef map<char,int> ormci;
- typedef set<int> orsi;
- typedef set<long long> orsll;
- typedef set<string> orss;
- typedef set<char> orsc;
- typedef vector<int> vi;
- typedef vector<string> vs;
- typedef vector<char> vc;
- typedef vector<ll> vll;
- typedef vector<vector<int>> vvi;
- typedef vector<vector<string>> vvs;
- typedef vector<vector<ll>> vvll;
- #define FOR(i, a, b) for (auto i=a; i<=(b); i++)
- #define FORd(i,b,a) for (int i =b; i >= a; i--)
- #define sz(x) (int)(x).size()
- #define mp make_pair
- #define pb push_back
- #define fi first
- #define se second
- #define ins insert
- const int MOD = 1000000007;
- //type functions here
- int cuts(string s)
- {
- int n=sz(s);
- if(n==1) return 0;
- int flag=0;
- for(int i=1;i<n;i++)
- {
- if(s[i-1]!=s[i])
- {
- flag=1;
- break;
- }
- }
- if(flag==0) return 0;
- if(n%2==1) return -1;
- int left,right;
- left=cuts(s.substr(0,n/2));
- right=cuts(s.substr(n/2,n));
- int count;
- //cout<<left<<" "<<right<<endl;
- if(left==0||right==0)
- count=0;
- else if(left==-1&&right==-1)
- return -1;
- else if(left==-1||right==-1)
- count=max(left,right);
- else
- count=min(left,right);
- return count+1;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int tc=1;
- cin>>tc;
- FOR(w,1,tc)
- {
- string s="bbbbbabbabba";
- cin>>s;
- int c=cuts(s);
- cout<<c<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement