Official
C - Domino Editorial by en_translator
Original proposer: ynymxiaolongbao
When a domino falls down to the right, any domino to its left has already fallen down.
Therefore, it is sufficient to mange “up to which domino has fallen down?” while scanning from the left to check whether it can fall down or not.
Sample code (Python)
N=int(input())
A=list(map(int,input().split()))
# We now that any domino with coordinate less than `crr` falls down
crr=1
for i in range(N):
# Determine if a domino at coordainte i can fall down
if i>=crr:
print(i)
exit()
crr=max(crr, i+A[i])
print(N)
posted:
last update: