luogu#P4804. [CCC 2016] 生命中的圆
[CCC 2016] 生命中的圆
Problem Description
Translated from CCC2016 Senior T5 “Circle of Life”
You may have heard of Conway's Game of Life. Conway's Game of Life runs on a grid matrix. However, it can produce very complex structures. In this problem, we will use a simplified version of the Game of Life.
This is a zero-player game. In other words, once the initial condition is given, the game runs by itself.
Divide a ring into segments, and label these segments clockwise as . Each segment is either alive (represented by 1) or dead (represented by 0).
The game will go through rounds of “changes”. If a cell has exactly one adjacent cell that is alive during this change, then the cell will be alive in the next change. Otherwise, the cell will be dead.
Given the initial state of the ring, find the state after changes.
Input Format
The first line contains two integers and .
The second line contains a string of length , describing the initial states of the cells. Each character is guaranteed to be either 0 or 1. The -th character represents the initial state of cell .
Output Format
Output a string of length , representing the final state. The format is the same as the input.
7 1
0000001
1000010
5 3
01011
10100
Hint
Sample Explanation 1
Cells , , and are adjacent, so they remain alive after one change.
Sample Explanation 2
After one change, the state is 00011.
After two changes, the state is 10111.
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
Note that for all testdata, you need to use 64-bit integers.
Translated by ChatGPT 5