CSES - HIIT Open 2018 - Results
Submission details
Task:Inversions
Sender:DROP TABLE
Submission time:2018-05-26 11:40:57
Language:Python3
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.38 sdetails
#2ACCEPTED0.42 sdetails
#3ACCEPTED0.45 sdetails
#4ACCEPTED0.47 sdetails
#5ACCEPTED0.41 sdetails

Code

bits = list(input().rstrip())
n = len(bits)
flip = False
valDict = {True: '1', False: '0'}
# true - 1
# false - 0
flip1 = 0
flip2 = 0
for i in range(n):
	#print(i)
	if bits[i] == valDict[flip]:
		flip1 += 1
		#print("incr flip1")
	else:
		#print("incr flip2")
		flip2 += 1
	flip = not flip
print(min(flip1, flip2))

Test details

Test 1

Verdict: ACCEPTED

input
000000000000000000000000000000...

correct output
500000

user output
500000

Test 2

Verdict: ACCEPTED

input
111111111111111111111111111111...

correct output
500000

user output
500000

Test 3

Verdict: ACCEPTED

input
010101010101010101010101010101...

correct output
0

user output
0

Test 4

Verdict: ACCEPTED

input
101010101010101010101010101010...

correct output
0

user output
0

Test 5

Verdict: ACCEPTED

input
110101011010110100100111110110...

correct output
499476

user output
499476