USACO Bronze 2016 January - Mowing the Field

Authors: Óscar Garries, Ryan Chou


Official Analysis (Java)

Implementation

We can simulate Farmer John's movements across his field and update our answer if he ever comes across the same patch of grass.

Time Complexity: O(NS)\mathcal{O}(NS)

Python

import sys
sys.stdin = open('mowing.in', 'r')
sys.stdout = open('mowing.out', 'w')
# Make a hashmap, and mark off steps.
# We'll first mark off his starting position.
visits = {1000 * 1000 + 1000: 0}
# FJ's starting position.
currX = 1000

C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define f first
#define s second

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!