ABC188C - ABC Tournament

考え方

トーナメントは再帰で一つ下の階層の勝者を求められる.

解法2がきれい.
Editorial - AtCoder Beginner Contest 188
(Pythonの例:Submission #19320967 - AtCoder Beginner Contest 188

回答例

N = int(input())
A = list(map(int, input().split()))

def f(depth, block):
    if depth == N:
        return block
    else:
        l = f(depth + 1, 2 * block)
        r = f(depth + 1, 2 * block + 1)
    if A[l] > A[r]:
        if depth == 0:
            return r
        else:
            return l
    else:
        if depth == 0:
            return l
        else:
            return r

print(f(0, 0) + 1)