More Common Tile Coloring
InterviewTime limit2sMemory limit1024 MB
Given an N by M letter grid, find the fewest cells to repaint so every K by K block matches one shared K by K pattern, and print the result.
- Level
Medium4 of 10
- Topics
- Array, Implementation, Greedy
- Solved
- No attempts yet
Problem
An tile is given. The cell at row , column is initially painted with color . Each color is a single uppercase English letter.
Split the tile into non-overlapping small tiles. Repaint some cells so that every small tile has the same color layout. The color used to repaint any cell must also be a single uppercase English letter.
Find the minimum number of cells that must be repainted, and print any one tile layout that satisfies this.
Input
The first line contains three integers , , and separated by spaces. and are multiples of .
The next lines contain a string of length , which is row of the tile colors. consists only of uppercase English letters.
Output
The first line prints the minimum number of cells that must be repainted.
The next lines print the repainted tile, where line is a string of length for row . The output strings also consist only of uppercase English letters.