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 NN segments, and label these NN segments clockwise as 1,,N1,\dots,N. Each segment is either alive (represented by 1) or dead (represented by 0).

The game will go through TT 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 TT changes.

Input Format

The first line contains two integers NN and T(3N100 000;1T1015)T(3 \le N \le 100\ 000;1 \le T \le 10^{15}).

The second line contains a string of length NN, describing the initial states of the NN cells. Each character is guaranteed to be either 0 or 1. The ii-th character represents the initial state of cell ii.

Output Format

Output a string of length NN, 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 11, N1N - 1, and NN 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 115\frac{1}{15} of the testdata, N15,T15N \le 15,T \le 15.

For another 615\frac{6}{15} of the testdata, N15N \le 15.

For another 415\frac{4}{15} of the testdata, N4000,T10 000 000N \le 4000,T \le 10\ 000\ 000.

Note that for all testdata, you need to use 64-bit integers.

Translated by ChatGPT 5