/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 13ms 2.863 MiB
#2 Wrong Answer 21ms 3.168 MiB
#3 Wrong Answer 13ms 2.828 MiB
#4 Wrong Answer 13ms 2.895 MiB
#5 Wrong Answer 12ms 2.844 MiB

Code

def count_swaps(s):
  # initialize the counts of zeros and ones
  zeros = 0
  ones = 0
  # loop through the string from left to right
  for c in s:
    # if the character is zero, increment the zeros count
    if c == '0':
      zeros += 1
    # if the character is one, increment the ones count
    else:
      ones += 1
  # the minimum number of swaps is the minimum of zeros and ones
  return min(zeros, ones)

# read the number of test cases
t = int(input())
# loop through the test cases
for _ in range(t):
  # read the size of the string
  n = int(input())
  # read the string
  s = input()
  # print the minimum number of swaps
  print(count_swaps(s))

Information

Submit By
Type
Submission
Problem
P1016 Swap sort
Language
Python 3 (Python 3.12.3)
Submit At
2024-01-07 14:44:54
Judged At
2024-01-07 14:44:54
Judged By
Score
0
Total Time
21ms
Peak Memory
3.168 MiB