#P4804. Circle of Life
Circle of Life
Circle of Life
This is a simplified version of Conway's Game of Life played on a circular arrangement of segments. The circle is divided into N segments, numbered 1 to N in clockwise order. Each segment is either alive (denoted by 1
) or dead (denoted by 0
).
The game evolves automatically for T rounds. In each round, every segment updates its state simultaneously according to the following rule:
New State = \(\begin{cases} 1 & \text{if exactly one adjacent segment is alive,}\\ 0 & \text{otherwise.} \end{cases}\)
Here, the two adjacent segments of a segment are the ones immediately clockwise and anticlockwise. Note that the circle is cyclic; thus, segment 1 is adjacent to segment N and segment 2, and segment N is adjacent to segment N-1 and segment 1.
Given the initial configuration of the circle, simulate the game for T rounds and output the final state as a string of N digits.
inputFormat
The input consists of two lines:
- The first line contains two integers
N
andT
(1 ≤ N, T ≤ some limit), whereN
is the number of segments andT
is the number of rounds. - The second line is a string of
N
characters, each of which is either0
or1
, representing the initial state of the segments in order.
outputFormat
Output a single line containing the final state of the circle after T
rounds, as a string of N
digits.
sample
8 1
01010101
00000000