#P6451. [COCI 2008/2009 #4] SLIKAR
[COCI 2008/2009 #4] SLIKAR
Description
He wants to paint a picture made of pixels, where is a power of (such as ). Each pixel will be colored either black or white. Josip already knows what his ideal painting looks like.
He will paint following these steps:
-
If the whole painting is a single pixel, he will color this pixel black or white according to his target.
-
Otherwise, he will split the square into four smaller squares, and then:
- Choose one of the squares and color it entirely white.
- From the remaining three squares, choose one and color it entirely black.
- Treat the remaining two squares as a new painting and repeat the steps above.
Soon he realized that it is impossible to paint his ideal picture exactly. Therefore, he wants you to write a program that makes the painted picture as close as possible to his ideal picture.
The difference between two pictures is the number of pixels whose colors are different.
Input Format
The first line contains an integer , the side length of the picture.
The next lines each contain digits or , describing the ideal picture, where each digit indicates whether the corresponding pixel is black or white.
Output Format
Output one integer on the first line: the minimum possible difference.
Then output lines, each containing digits or , describing the actual colors of the pixels.
Note: there may be multiple valid coloring plans. Output any one. This problem uses SPJ.
4
0001
0001
0011
1110
1
0001
0001
0011
1111
4
1111
1111
1111
1111
6
0011
0011
0111
1101
8
01010001
10100011
01010111
10101111
01010111
10100011
01010001
10100000
16
00000001
00000011
00000111
00001111
11110111
11110011
11110001
11110000
Hint
Constraints
- For of the testdata, .
- For of the testdata, .
Notes
Translated from COCI2008-2009 CONTEST #4 T4 SLIKAR.
Translated by ChatGPT 5
京公网安备 11011102002149号