XorBoardDivTwo
SRM 555 · 2012-06-05 · by wrong
Problem Statement
Fox Jiro has a rectangular board, divided into a grid of square cells.
Each cell in the grid contains either the character '0', or the character '1'.
The
Jiro now has to make exactly two flips. In the first flip, he must pick a row and flip all characters in that row. (When flipped, a '0' turns to a '1' and vice versa.) In the second flip, he must pick a column and flip all characters in that column.
You are given the
Constraints
- board will contain between 1 and 50 elements, inclusive.
- Each element of board will contain the same number of characters.
- Each element of board will contain between 1 and 50 characters, inclusive.
- Each character in board will be '0' or '1'.
{"101",
"010",
"101"}
Returns: 9
Jiro can obtain 9 '1's by flipping the center row and then the center column.
{"111",
"111",
"111"}
Returns: 5
Jiro has to make both flips, even if that decreases the number of '1's.
{"0101001",
"1101011"}
Returns: 9
{"000",
"001",
"010",
"011",
"100",
"101",
"110",
"111"}
Returns: 15
{"000000000000000000000000",
"011111100111111001111110",
"010000000100000001000000",
"010000000100000001000000",
"010000000100000001000000",
"011111100111111001111110",
"000000100000001000000010",
"000000100000001000000010",
"000000100000001000000010",
"011111100111111001111110",
"000000000000000000000000"}
Returns: 105
Submissions are judged against all 70 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class XorBoardDivTwo with a public method int theMax(vector<string> board) · 70 test cases · 2 s / 256 MB per case