Connection Status:
Competition Arena > CellLife
SRM 107 · 2002-08-05 · by dgoodman
Class Name: CellLife
Return Type: int
Method Name: diversity
Arg Types: (string)
Problem Statement

Problem Statement

We are interested in how much biological diversity can be generated by very simple life and death rules. The environment is a line of cells. Each cell may either be alive or dead.

We will define the diversity in a line of cells to be the number of different sizes of alive groups that are present. An alive group is a contiguous set of alive cells. So a line of cells AADADDDADDDAAAADDADDA has diversity equal to 3 since it contains alive groups of sizes 2, 1, and 4.

Create a class CellLife that contains a method diversity that takes a configuration of cells as input and returns its diversity.

Constraints

  • line contains between 1 and 50 characters, inclusive.
  • Each character in line is 'A' or 'D'.
Examples
0)
"ADDAADD"
Returns: 2

This line has a group of size 1 and a group of size 2

1)
"ADDAAADAAAD"
Returns: 2

This line has groups of size 1 and size 3

2)
"DDD"
Returns: 0
3)
"ADAADAAADAAAADAAAAADAAAAADADDDDD"
Returns: 5
4)
"ADADADADADADADADADADADADADADADADADADADADADADA"
Returns: 1

Submissions are judged against all 29 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class CellLife with a public method int diversity(string line) · 29 test cases · 2 s / 256 MB per case

Submitting as anonymous