USACO Silver 2016 January - Build Gates

Author: Maggie Liu

Official Analysis

Warning!

The official solution stores the farm in a 2005×20052005 \times 2005 boolean array with the origin at (1002,1002)(1002, 1002), but this is not sufficient. Since each fence segment is doubled, the maximum distance in each direction could be 20002000 units, causing an input such as 10001000 N\texttt{N}s to go out of bounds. To not go out of bounds, an array of size 4003×40034003 \times 4003 should be used: 11 unit for the origin position, 20002000 units in each direction from the origin and 11 more unit in each direction to ensure that the farm includes area beyond the fence.

C++

Implementation

#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
void ff(int i, int j);
bool fence[4003][4003] = {false};
bool visited[4003][4003] = {false};
int maxx = 2001, minx = 2001, maxy = 2001, miny = 2001;
int main()

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!