/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 15ms 3.016 MiB
#2 Time Exceeded ≥2099ms ≥4.074 MiB
#3 Wrong Answer 1492ms 3.02 MiB

Code

t=int(input())
if 1 <= t <= 1000:
    for i in range(t):
        n = int(input())
        s = input()
        count = 0
        odd = 0
        S = list(s)
        if 1<=n<=10**5:
            for j in range(n):
                if S[j] == '0':
                    for c in range(j + 1, n):
                        if S[c] == '1':
                            S[j], S[c] = S[c], S[j]
                            count += 1

            for k in range(n):
                if S[k] == '1':
                    for b in range(k + 1, n):
                        if S[b] == '0':
                            S[k], S[b] = S[b], S[k]
                            odd += 1

            if count < odd:
                print(count)
            elif odd < count:
                print(odd)
            elif odd == count:
                print(odd)

Information

Submit By
Type
Submission
Problem
P1016 Swap sort
Language
Python 3 (Python 3.12.3)
Submit At
2024-01-07 15:26:03
Judged At
2024-11-11 03:43:43
Judged By
Score
20
Total Time
≥2099ms
Peak Memory
≥4.074 MiB