Accepted
Code
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int n; cin>>n;
string s; cin>>s;
int one=0,zero=0;
for(auto x:s) one+=(x=='1'), zero+=(x=='0');
int ans1=0,ans2=0;
for(int i=0;i<one;i++)
{
if(s[i]=='0') ans1++;
}
for(int i=0;i<zero;i++)
{
if(s[i]=='1') ans2++;
}
cout<<min(ans1,ans2)<<endl;
}
int main(){int t; cin>>t; while(t--) solve();}
Information
- Submit By
- Type
- Submission
- Problem
- P1016 Swap sort
- Language
- C++20 (G++ 13.2.0)
- Submit At
- 2023-12-07 16:22:29
- Judged At
- 2024-11-11 03:49:18
- Judged By
- Score
- 100
- Total Time
- 6ms
- Peak Memory
- 584.0 KiB