TaroGrid
SRM 631 · 2014-07-26 · by Witaliy
Problem Statement
Cat Taro has a square grid with N rows and N columns.
Each cell of the grid is painted either black or white.
You are given a
Taro wants to choose a set of consecutive cells that are in the same column and are painted in the same color. Return the largest number of cells he can choose.
Constraints
- N will be between 1 and 50, inclusive.
- grid will contain exactly N elements.
- Each element of grid will contain exactly N characters.
- Each character in grid will be 'W' or 'B'.
{"W"}
Returns: 1
{"WB",
"BW"}
Returns: 1
{"BWW",
"BBB",
"BWB"}
Returns: 3
He can choose the entire leftmost column (i.e., character 0 of each element of grid).
{"BWBW",
"BBWB",
"WWWB",
"BWWW"}
Returns: 3
{"BWB",
"BBW",
"BWB"}
Returns: 3
{"BBWWBBWW",
"BBWWBBWW",
"WWBBWWBB",
"WWBBWWBB",
"BBWWBBWW",
"BBWWBBWW",
"WWBBWWBB",
"WWBBWWBB"}
Returns: 2
Note that the chosen cells must be consecutive.
Submissions are judged against all 91 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TaroGrid with a public method int getNumber(vector<string> grid) · 91 test cases · 2 s / 256 MB per case