308454: CF1523A. Game of Life

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Game of Life

题意翻译

$ t $ 组测试数据,每组给定 $ 01 $ 串的长度 $ n $ 和轮数 $ m $。 对于每一轮,每个有且仅有一个 $ 1 $ 与之相邻的 $ 0 $ 会变成 $ 1 $。例 $ 101 $ 中的 $ 0 $ 不会变成 $ 1 $,但 $ 1000001 $ 经过 $ 2 $ 轮后变成 $ 1110111 $。 每组测试数据输出经过 $ m $ 轮后的 $ 01 $ 串并换行。 $ 1 \le t \le {10}^3 $,$ 2 \le n \le {10}^3 $,$ 1 \le m \le {10}^9 $,保证所有 $ n $ 的总和不超过 $ {10}^4 $。

题目描述

![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1523A/010268700b5eefe6d637a339a161b9e30121cb66.png)William really likes the cellular automaton called "Game of Life" so he decided to make his own version. For simplicity, William decided to define his cellular automaton on an array containing $ n $ cells, with each cell either being alive or dead. Evolution of the array in William's cellular automaton occurs iteratively in the following way: - If the element is dead and it has exactly $ 1 $ alive neighbor in the current state of the array, then on the next iteration it will become alive. For an element at index $ i $ the neighbors would be elements with indices $ i - 1 $ and $ i + 1 $ . If there is no element at that index, it is considered to be a dead neighbor. - William is a humane person so all alive elements stay alive. Check the note section for examples of the evolution. You are given some initial state of all elements and you need to help William find the state of the array after $ m $ iterations of evolution.

输入输出格式

输入格式


Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 10^3 $ ). Description of the test cases follows. The first line of each test case contains two integers $ n $ and $ m $ ( $ 2 \le n \le 10^3, 1 \le m \le 10^9 $ ), which are the total number of cells in the array and the number of iterations. The second line of each test case contains a string of length $ n $ made up of characters "0" and "1" and defines the initial state of the array. "1" means a cell is alive and "0" means it is dead. It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 10^4 $ .

输出格式


In each test case output a string of length $ n $ , made up of characters "0" and "1" — the state of the array after $ m $ iterations of evolution.

输入输出样例

输入样例 #1

4
11 3
01000000001
10 2
0110100101
5 2
10101
3 100
000

输出样例 #1

11111001111
1110111101
10101
000

说明

Sequence of iterations of evolution for the first test case - 01000000001 — initial state - 11100000011 — first iteration of evolution - 11110000111 — second iteration of evolution - 11111001111 — third iteration of evolution Sequence of iterations of evolution for the second test case - 0110100101 — initial state - 1110111101 — first iteration of evolution - 1110111101 — second iteration of evolution

Input

题意翻译

$ t $ 组测试数据,每组给定 $ 01 $ 串的长度 $ n $ 和轮数 $ m $。 对于每一轮,每个有且仅有一个 $ 1 $ 与之相邻的 $ 0 $ 会变成 $ 1 $。例 $ 101 $ 中的 $ 0 $ 不会变成 $ 1 $,但 $ 1000001 $ 经过 $ 2 $ 轮后变成 $ 1110111 $。 每组测试数据输出经过 $ m $ 轮后的 $ 01 $ 串并换行。 $ 1 \le t \le {10}^3 $,$ 2 \le n \le {10}^3 $,$ 1 \le m \le {10}^9 $,保证所有 $ n $ 的总和不超过 $ {10}^4 $。

加入题单

算法标签: