그룹을 나누는 함수(div)와 승자를 결정하는 함수(calc)를 생성했다.
def calc(x,y):
if (arr[x-1]==1 and arr[y-1]==3) or (arr[x-1]==1 and arr[y-1]==1):
return x
elif (arr[x-1]==2 and arr[y-1]==1) or (arr[x-1]==2 and arr[y-1]==2):
return x
elif (arr[x-1]==3 and arr[y-1]==2) or (arr[x-1]==3 and arr[y-1]==3):
return x
return y
def div(start,end):
if start==end:
return start
ar1= div(start, (start+end)//2)
ar2 = div((start+end)//2+1, end)
return calc(ar1,ar2)
for tc in range(1,int(input())+1):
N = int(input())
arr=list(map(int, input().split()))
print(f'#{tc} {div(1,N)}')
텍스트