-
Notifications
You must be signed in to change notification settings - Fork 0
/
max1Xor.cpp
58 lines (42 loc) · 901 Bytes
/
max1Xor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// codechef , MAX1XOR
#include <bits/stdc++.h>
using namespace std;
// #define ll long long
void solve(){
int n;
cin>>n;
string s;
cin>>s;
int arrS[n];
for(int i = 0;i<n;i++){
(s[i]=='0')?arrS[i]=0:arrS[i]=1;
}
cout<<endl;
int arrX[n]={0};
int arrX2[n]={0};
arrX2[0] = 1;
for(int i = 0;i<n-1;i++){
arrX[i+1] = arrX[i]^arrS[i];
arrX2[i+1] = arrX2[i]^arrS[i];
}
int count = 0;
int count2 = 0;
for(int i = 0;i<n;i++){
if(arrX[i]==1) count++;
if(arrX2[i]==1) count2++;
}
cout<<max(count,count2)<<endl;
}
int main()
{
// for multiple testcases
// int t;
// cin >> t;
// while (t--)
// {
// solve();
// }
// for single test case
solve();
return 0;
}