이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.
문제
This task concerns the output length of the quadtree image compression scheme. Only L×L images consisting of L2 pixels are considered. An image pixel is either a 0-pixel or a 1-pixel.
The quadtree image compression scheme is as follows:
If the image consists of both 0-pixels and 1-pixels, encode a 1 to indicate that the image will be partitioned into 4 sub-images as described in Step (2). Otherwise, encode the entire image as 00 or 01 to indicate that the image consists of only 0-pixels or only 1-pixels respectively.
An image I is partitioned into 4 equal size sub-images A, B, C, D as shown:
[이미지 1]
Step (1) is then performed on each of the four sub-images in the order of A, B, C, D.
Let (I) be the encoding of the image I. The following examples show the encoding process to compress an image.
Example 1. This example shows the encoding process of a 4×4 image.
Thus the length of the compressed image is 9 (bits).
Read an L×L image (1≤L≤64 and L is a power of 2) from the input.
Compute the length (the number of bits) of the compressed image encoded by the quadtree compression scheme.
Write the length to the output.
입력
For an L×L square image, the input file contains L+1 lines. The first line consists of the single integer L. Each line of the subsequent L lines consists of L bits (a bit is either a 0 or a 1) with a blank between two adjacent bits.
출력
The output file consists of one integer which is the length (the number of bits) in the compressed image.