Connection Status:
Competition Arena > TaroGrid
SRM 631 · 2014-07-26 · by Witaliy · Brute Force, Simple Search, Iteration
Class Name: TaroGrid
Return Type: int
Method Name: getNumber
Arg Types: (vector<string>)
Problem Statement

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 String[] grid which represents the current state of the grid. Each element of grid represents one row of the grid. In grid, the character 'W' represents a white cell, and the character 'B' represents a black cell.

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'.
Examples
0)
{"W"}
Returns: 1
1)
{"WB",
 "BW"}
Returns: 1
2)
{"BWW",
 "BBB",
 "BWB"}
Returns: 3

He can choose the entire leftmost column (i.e., character 0 of each element of grid).

3)
{"BWBW",
 "BBWB",
 "WWWB",
 "BWWW"}
Returns: 3
4)
{"BWB",
 "BBW",
 "BWB"}
Returns: 3
5)
{"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.

Coding Area

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

Submitting as anonymous