PinterestOA #5
Bubble Explosion
估计中等可在线判题
考点(AI 标注)网格搜索模拟/实现
On the board, bubbles of the same color that are adjacent up, down, left, or right form connected groups. A bubble is eligible to explode if it has at least two neighbors of the same color; all eligible bubbles and their same-colored neighbors explode simultaneously. Then the remaining bubbles in each column fall down, and empty cells are represented by 0. The process ends after a single explosion.
输入格式
The first line contains rows cols; each of the next rows lines contains cols color integers. Source constraints: 1≤rows,cols≤100, 1≤color≤10⁴.
输出格式
Output the rows×cols matrix after the explosion and the fall, with each row space-separated.
样例 1
输入:
4 4
3 1 2 1
1 1 1 4
3 1 2 2
3 3 3 4
输出:
0 0 0 1
0 0 0 4
0 0 2 2
3 0 2 4
样例 2
输入:
2 3
1 2 2
1 1 2
输出:
0 0 0
0 0 0
样例 3
输入:
1 1
1
输出:
1