HouseBuilding
TCO13 Round 1A · 2013-02-19 · by gojira_tc
TCO13 Round 1A · 2013-02-19 · by gojira_tc · Simple Search, Iteration
Problem Statement
Problem Statement
Manao is building a new house. He already purchased a rectangular area where he will place the house. The basement of the house should be built on a level ground, so Manao will have to level the entire area. The area is leveled if the difference between the heights of its lowest and highest square meter is at most 1. Manao wants to measure the effort he needs to put into ground leveling.
You are given aString[] area. Each character in area denotes the height at the corresponding square meter of Manao's area. Using 1 unit of effort, Manao can change the height of any square meter on his area by 1 up or down. Return the minimum total effort he needs to put to obtain a leveled area.
You are given a
Constraints
- area will contain between 1 and 50 elements, inclusive.
- Each element of area will be between 1 and 50 characters long, inclusive.
- All elements of area will be of the same length.
- Each element of area will contain digits ('0'-'9') only.
Examples
0)
{"10",
"31"}
Returns: 2
The given area is not leveled, because the minimum height is 0 and the maximum height is 3. Manao needs to reduce the height of lower left square by 2.
1)
{"54454",
"61551"}
Returns: 7
In the optimal solution each square will have height either 4 or 5. To reach such a configuration, Manao should reduce the height of one square from 6 to 5, and increase the heights of two other squares from 1 to 4.
2)
{"989"}
Returns: 0
The area is already leveled.
3)
{"90"}
Returns: 8
4)
{"5781252",
"2471255",
"0000291",
"1212489"}
Returns: 53
Submissions are judged against all 127 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class HouseBuilding with a public method int getMinimum(vector<string> area) · 127 test cases · 2 s / 256 MB per case