We can simulate Farmer John's movements across his field and update our answer when he comes across the same patch of grass.
Implementation
Time Complexity:
with open("mowing.in") as read:n = int(read.readline())steps = []for _ in range(n):dir_, num_steps = map(str, read.readline().split())steps.append((dir_, int(num_steps)))# FJ's starting position.curr = (0, 0)# Make a hashmap, and mark off steps.
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!