/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 25ms 3.07 MiB
#2 Time Exceeded ≥2029ms ≥4.055 MiB
#3 Time Exceeded ≥2014ms ≥3.16 MiB

Code

t=int(input())
for i in range(t):
    n=int(input())
    s=input()
    count=0
    odd=0
    S=list(s)
    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 14:42:08
Judged At
2024-11-11 03:43:43
Judged By
Score
20
Total Time
≥2029ms
Peak Memory
≥4.055 MiB