ThreeMines
SRM 315 · 2006-08-09 · by Cosmin.ro
Problem Statement
You are given a String[] field where each character represents the profit value of a single cell. Characters 'a' to 'z' correspond to the numbers 0 through 25 and characters 'B' to 'Z' correspond to numbers -1 through -25. The jth char in the ith element of field is the profit value of the cell at row i, column j.
Constraints
- field will contain between 1 and 30 elements, inclusive.
- Each element of field will contain between 1 and 30 characters, inclusive.
- Each character of field will be from the set 'a'..'z' and 'B'..'Z'.
- All elements of field will contain the same number of characters.
- field must contain at least 3 cells.
Statement by TopCoder, Inc. — view the original on the archive.
{
"bbbb",
"bBBB",
"BBbb",
"BBBB"}
Returns: 7
One of the optimal solutions is the following: One mine contains all cells in the first row, the second mine contains the cell (1, 0), and the third mine contains the cells (2, 2) and (2, 3).
{"cfCBDCbcdZb"}
Returns: 14
A single row example.
{"d", "c", "B", "m", "Z", "h", "g", "B", "z", "G", "H", "b", "Y"}
Returns: 54
A single column example.
{
"hBhh",
"BBBB",
"BBBB",
"hBhh",
"hBhh"}
Returns: 62
This test has only one solution.
{
"BB",
"BB"}
Returns: -3
It is possible for the maximum possible profit to be negative.
{"aaaaaa", "aBddBa", "adzzda", "adzHaa", "abdaaa", "aaaaaa"}
Returns: 94
greedy testcase
{"hBZaBz","dhbhhB","dhbBaa","cBZaaa"}
Returns: 69
hBZaBz dhbhhB dhbBaa cBZaaa
Submissions are judged against all 75 archived test cases, of which 7 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ThreeMines with a public method int maximumProfit(vector<string> field) · 75 test cases · 2 s / 256 MB per case