AlienAndGame
SRM 605 · 2013-12-22 · by Witaliy
Problem Statement
Alien Fred wants to destroy the Earth. But before he does that, he wants to play the following game.
He has a rectangular board divided into unit cells.
Each cell is initially painted black or white.
You are given a
Fred wants to have a large white square somewhere on his board. The sides of Fred's square must be parallel to the sides of the board. The white square may be a part of a larger white area. (I.e., the cells that touch the square may be both black and white.) Find a sequence of turns that produces the largest possible white square somewhere on the board, and return the area of that square.
Constraints
- board will contain between 1 and 50 elements, inclusive.
- Each element of board will contain between 1 and 50 characters, inclusive.
- Each element of board will contain the same number of characters.
- Each character in each element of board will be either 'B' or 'W'.
{"BB",
"WW"}
Returns: 4
The optimal strategy is to repaint row 0. After this change the entire board will be white, and thus we have a 2*2 white square.
{"W"}
Returns: 1
Sometimes the optimal strategy requires no repainting.
{"WBBB",
"WBBB",
"WWWW"}
Returns: 9
We should repaint row 0 and then repaint row 1. The resulting board will contain a 3*3 white square (in rows 0-2 and columns 1-3).
{"W",
"B",
"W",
"W",
"W"}
Returns: 1
{"BWBBWBB",
"WWBWWBW",
"BBBBBBW",
"WBBBBWB",
"BBWWWWB",
"WWWWWWW",
"BBWWBBB"}
Returns: 9
Submissions are judged against all 83 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class AlienAndGame with a public method int getNumber(vector<string> board) · 83 test cases · 2 s / 256 MB per case