/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Accepted 6ms 584.0 KiB
#3 Accepted 2ms 540.0 KiB
#4 Accepted 2ms 332.0 KiB
#5 Accepted 2ms 336.0 KiB

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