GameOfLifeDivOne
SRM 511 · 2011-05-25 · by rng_58
Problem Statement
N cells are arranged around a circle. The cells are numbered from 0 to N-1. For each i between 0 and N-2, inclusive, the i-th cell and the (i+1)-th cell are adjacent to each other. The (N-1)-th cell and the 0-th cell are adjacent to each other. Each cell has exactly two adjacent cells. Each cell has a state: "live" or "die".
Taro and Hanako can decide the states of the cells at time 0. For time t > 0, the states are determined as follows:
- Consider three cells: the i-th cell and the two cells that are adjacent to the i-th cell.
- If at least two of the three cells are "live" at time t-1, the state of the i-th cell at time t will be "live".
- If at least two of the three cells are "die" at time t-1, the state of the i-th cell at time t will be "die".
Constraints
- init will contain between 3 and 50 characters, inclusive.
- Each character in init will be '0' (zero), '1' (one) or '?'.
- T will be between 0 and 1,000, inclusive.
- K will be between 0 and the number of characters in init, inclusive.
"0?1" 1 1 Returns: 1
There are two ways to replace '?' with '0' and '1': "001" and "011". If the state is "001" at time 0, the state will be "000" at time 1. No cell is in the "live" state. If the state is "011" at time 0, the state will be "111" at time 1. 3 cells are in the "live" state. Only the second one satisfies the condition, so the answer is 1.
"?????????" 0 1 Returns: 511
There are 512 ways to replace '?' cells with '0' or '1'. All of them except "000000000" satisfy the condition.
"??0???????" 58 6 Returns: 151
"?????????1" 47 3 Returns: 453
"??01??110?" 100 3 Returns: 29
Submissions are judged against all 121 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class GameOfLifeDivOne with a public method long long theCount(string init, int T, int K) · 121 test cases · 2 s / 256 MB per case