Codejam Qualification Round 2018. Task 2
Python Only
def trouble_sort(L,N):
LE,LO=[],[]
for i in range(N):
(LO,LE)[i%2==0].append(L[i])
LE=sorted(LE)
LO=sorted(LO)
L=sorted(L)
for i in range(N):
if i%2==0:
el=LE[i//2]
else:
el=LO[i//2]
if el!=L[i]:
break
if N-1!=i:
return str(i)
else:
return 'OK'
T=int(input())
for t in range(T):
N=int(input())
L=list(map(int,input().split()))
ANS=trouble_sort(L,N)
print('Case #{}: {}'.format(t+1,ANS))
No comments:
Post a Comment