Connection Status:
Competition Arena > XorBoardDivTwo
SRM 555 · 2012-06-05 · by wrong · Brute Force, Simple Search, Iteration
Class Name: XorBoardDivTwo
Return Type: int
Method Name: theMax
Arg Types: (vector<string>)
Problem Statement

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 String[] board contains the current state of the board. The j-th character of the i-th element of board is the character in row i, column j of the grid.


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 String[] board. Return the maximum number of '1's in the grid after Jiro makes the two flips.

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'.
Examples
0)
{"101",
 "010",
 "101"}
Returns: 9

Jiro can obtain 9 '1's by flipping the center row and then the center column.

1)
{"111",
 "111",
 "111"}
Returns: 5

Jiro has to make both flips, even if that decreases the number of '1's.

2)
{"0101001",
 "1101011"}
Returns: 9
3)
{"000",
 "001",
 "010",
 "011",
 "100",
 "101",
 "110",
 "111"}
Returns: 15
4)
{"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.

Coding Area

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

Submitting as anonymous