-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAND_OR_Sort!.cpp
More file actions
47 lines (44 loc) · 860 Bytes
/
Copy pathAND_OR_Sort!.cpp
File metadata and controls
47 lines (44 loc) · 860 Bytes
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
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
void solve(){
int n;
cin>>n;
string str;
cin>>str;
vector<int> a;
long long ans =0;
long long cnt0 =0;
if(str[0]=='1'){
for(int i=0;i<str.size();i++){
if(str[i]-'0'==0){
cnt0++;
}
}
cout<<cnt0<<endl;
}else{
long long cnt0 =0;
for(int i=0;i<n;i++){
if(str[i]=='0')cnt0++;
}
long long minn =INT_MAX;
long long cnt1=0;
for(int i=0;i<n;i++){
if(str[i]=='0')cnt0--;
if(str[i]=='1')cnt1++;
minn = min(minn,cnt1+cnt0);
ans =minn;
}
cout<<ans<<endl;
}
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int T =1;
cin>>T;
while(T--){
solve();
}
return 0;
}