You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
473 B
19 lines
473 B
def next(num, turn, memo):
|
|
if num not in memo:
|
|
memo[num] = (0, turn)
|
|
return 0
|
|
memo[num] = (memo[num][1], turn)
|
|
return memo[num][1] - memo[num][0]
|
|
|
|
|
|
def solve(input, target):
|
|
memo, n = {}, input[-1]
|
|
for i, j in enumerate(input):
|
|
memo[j] = (0, i)
|
|
for t in range(len(input)-1, target-1):
|
|
n = next(n, t, memo)
|
|
return n
|
|
|
|
|
|
print(solve([16, 12, 1, 0, 15, 7, 11], 2020))
|
|
print(solve([16, 12, 1, 0, 15, 7, 11], 30000000))
|
|
|