WaterPressure
TCO '03 Round 3 · 2003-10-07 · by brett1479
Problem Statement
- 1) Each second, beginning with second 0, the total amount of water increases by 1 in the squares where water has reached.
- 2) The total water pressure is equal to the total amount of water divided by the total number of squares the water has reached. This need not be an integral amount.
- 3) At the end of each second, after the total amount of water has been incremented, each square adjacent to the water (not diagonally) is checked for strength. Every adjacent square, whose digit value is strictly smaller than the total water pressure, will become covered with water.
Notes
- Total water pressure need not be an integer.
Constraints
- layout will contain between 1 and 50 elements inclusive.
- Each element of layout will contain between 1 and 50 characters inclusive.
- Each element of layout will contain the same number of characters.
- The 0th character in the 0th element of layout will be (quotes for clarity) '.' . Every other character in layout will be a digit ('0'-'9') or 'X'.
- layout will contain at least one digit.
{
".0",
"0X"}
Returns: 0
During second 0 the total water will be incremented to 2. Thus, the total pressure is 2. This is clearly greater than 0, so both '0' squares will be flooded. Since no digit squares remain unflooded, your method returns 0.
{
".0",
"00"}
Returns: 1
Once second 0 is complete: Total water = 2 Total filled = 3 Total pressure = 2/3 Current layout ('.' denotes flooded): ".. .0" During second 1 the final digit containing square is flooded.
{
".5",
"44"}
Returns: 14
{".23456789"}
Returns: 71
{
".X0",
"X00"}
Returns: -1
The 'X' blocks the digit containing squares. Since the water can never reach the '0's, your method returns -1.
Submissions are judged against all 101 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class WaterPressure with a public method int howLong(vector<string> layout) · 101 test cases · 2 s / 256 MB per case