USACO 2016 January Silver: Build Gates

Problem Link

I tried the problem (above), but the solution code provided by USACO doesn’t really make sense. Could someone perhaps explain that solution or provide another Flood Fill solution, perhaps involving a recursive floodfill approach.

I drew out the sample case, but I’m not really sure if my thought process concurs with what the problem states as “gates”.

Here is my fence drawing:

Screenshot 2021-01-29 092124

What doesn’t really make sense about the code? (btw i can give you my code if you think it’ll help)

Sure, that’d be helpful.

Why dirx is -1 when dir = ‘N’

Here. It’s in Java though, so I can’t help you if you were looking for a C++ version.

1 Like

For some reason they inverted all the directions. I guess(?) it makes working with array indices easier?

1 Like

Does anyone here have a recursive solution?