欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1523A.Game of Life
Game of Life

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 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 alive neighbor in the current state of the array, then on the next iteration it will become alive. For an element at index the neighbors would be elements with indices and . 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 iterations of evolution.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). Description of the test cases follows.
The first line of each test case contains two integers and (), 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 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 over all test cases does not exceed .
Output
In each test case output a string of length , made up of characters "0" and "1" — the state of the array after iterations of evolution.
Note
Sequence of iterations of evolution for the first test case
01000000001— initial state11100000011— first iteration of evolution11110000111— second iteration of evolution11111001111— third iteration of evolution
Sequence of iterations of evolution for the second test case
0110100101— initial state1110111101— first iteration of evolution1110111101— second iteration of evolution
Samples
4
11 3
01000000001
10 2
0110100101
5 2
10101
3 100
000
11111001111
1110111101
10101
000
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |