/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 14ms 3.02 MiB
#2 Wrong Answer 20ms 3.18 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-11-11 03:43:43
Judged By
Score
0
Total Time
20ms
Peak Memory
3.18 MiB