Squares
SRM 332 · 2006-12-28 · by andrewzta
Problem Statement
You are given a rectangular field divided into square cells. Each cell contains a letter. A square with vertices in the centers of four cells is called valid if those four cells are distinct and all contain the same letter. For example, the following field contains two valid squares:
ABA BAB ABA
One has vertices in the centers of the following squares:
A.A ... A.A
Another has vertices in the centers of the following cells:
.B. B.B .B.
You are given a
Constraints
- field will contain between 1 and 50 elements, inclusive.
- Each element of field will contain between 1 and 50 characters, inclusive.
- All elements of field will contain the same number of characters.
- Each element of field will contain only uppercase letters ('A'-'Z').
{"ABA", "BAB", "ABA"}
Returns: 2
Example from the problem statement.
{"AA", "AA"}
Returns: 1
{"ABC", "DEF", "GHI"}
Returns: 0
There are no valid squares here.
{"AABCA", "AAAAA", "BAAAB", "AAAEA", "ADBFA"}
Returns: 11
{"A"}
Returns: 0
Submissions are judged against all 122 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Squares with a public method int countSquares(vector<string> field) · 122 test cases · 2 s / 256 MB per case