AmoebaDivTwo
SRM 493 · 2010-11-01 · by K.A.D.R
Problem Statement
Little Romeo likes cosmic amoebas a lot. Recently he received one as a gift from his mother. He decided to place his amoeba on a rectangular table. The table is a grid of square 1x1 cells, and each cell is occupied by either matter or antimatter. The amoeba is a rectangle of size 1xK. Romeo can place it on the table in any orientation as long as every cell of the table is either completely covered by part of the amoeba or completely uncovered, and no part of the amoeba lies outside of the table. It is a well-known fact that cosmic amoebas cannot lie on top of matter, so every cell of the table covered by the amoeba must only contain antimatter.
You are given a
Constraints
- table will contain between 1 and 50 elements, inclusive.
- Each element of table will contain between 1 and 50 characters, inclusive.
- All elements of table will have the same length.
- Each character of each element of table will be either 'A' or 'M'.
- K will be between 1 and 50, inclusive.
{"MA"}
2
Returns: 0
The amoeba requires a 1x2 or 2x1 rectangle containing only antimatter, but there is no such space available on the table.
{"AAA",
"AMA",
"AAA"}
3
Returns: 4
{"AA",
"AA",
"AA"}
2
Returns: 7
Here are all 7 configurations, where X represents the amoeba: XX .. .. X. .X .. .. .. XX .. X. .X X. .X .. .. XX .. .. X. .X
{"MMM",
"MMM",
"MMM"}
1
Returns: 0
There are no cells with antimatter at all.
{"A"}
1
Returns: 1
Submissions are judged against all 90 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class AmoebaDivTwo with a public method int count(vector<string> table, int K) · 90 test cases · 2 s / 256 MB per case