VegetableGarden
SRM 340 · 2007-02-20 · by Mike Mirzayanov
Problem Statement
Your vegetable garden forms a rectangular grid of equal square plots. You've decided to inspect some of your plots. Starting at the top left corner, you will walk through the garden and return back to your starting point. All plots that lie inside the cycle of your path will be considered inspected. You are not allowed to walk inside the plots; you can only walk along their boundaries. Your path must not intersect itself. The boundaries are wide enough that you can walk along the same boundary multiple times without intersecting your own path.
You are given a
Constraints
- garden will contain between 1 and 50 elements, inclusive.
- Each element of garden will contain only periods ('.'), uppercase 'I's and uppercase 'X's.
- Each element of garden will contain an equal number of characters.
- Each element of garden will contain between 1 and 50 characters, inclusive.
- garden will contain between 1 and 10 characters that are not periods ('.').
{"I"}
Returns: {4 }
Walk around the periphery of the plot.
{"XX",
"XI"}
Returns: {8 }
{"III",
"IXI",
"III"}
Returns: {4, 6, 8, 10, 12, 14, 16, 18 }
An example of inspecting 8 plots is below.
{"X.I",
".I.",
"I.."}
Returns: {8, 10, 14 }
{"IIXIIXIXII"}
Returns: {4, 6, 12, 14, 20, 26, 28 }
Submissions are judged against all 132 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class VegetableGarden with a public method vector<int> getMinDistances(vector<string> garden) · 132 test cases · 2 s / 256 MB per case