Accepted
Code
def solve():
n=int(input())
s=input()
one=0
zero=0
for x in s:
one+=(x=='1')
zero+=(x=='0')
ans1=0
ans2=0
for i in range(one):
if(s[i]=='0'):
ans1+=1
for i in range(zero):
if(s[i]=='1'):
ans2+=1
print(min(ans1,ans2))
t = int(input())
for _ in range(t):
solve()
Information
- Submit By
- Type
- Submission
- Problem
- P1016 Swap sort
- Language
- Python 3 (Python 3.12.3)
- Submit At
- 2023-12-10 20:30:23
- Judged At
- 2024-11-11 03:48:58
- Judged By
- Score
- 100
- Total Time
- 35ms
- Peak Memory
- 3.234 MiB