시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 64 17 15 34.091%

문제

보물 사냥꾼인 한신이는 6576번 아즈텍 문명의 유적지에서 가져온 보물지도가 가짜라는 것을 알게되었다. 이것에 화가난 한신이는 자신뿐만 아니라 다른사람에게도 이 거짓 지도를 보내서 장난을 칠 계획을 가지게 된다. 이 지도도를 아무나 읽을수 있다면 한신이가 매우 곤란해진다. 이것을 위해 한신이를 도와주자!

지도는 XBM 형식이며 이것을 쿼드 트리 구조로 암호화하여 보낼것이다. 가능하겠는가?

입력

  • 첫 번째 줄에는 "#define quadtree_width n"가 입력이 되는데 여기서 n은 가로 픽셀 크기를 의미한다. (이 사진은 n*n 픽셀이다.)
  • 두 번째 줄에는 "#define quadtree_height n"가 입력이 되는데 여기서 n은 세로 픽셀 크기를 의미한다.
  • 세 번째 줄에는 "static char quadtree_bits[] = {"가 입력된다.
  • 그리고 다음 n줄에는 사진 한줄의 픽셀값이 n/8개의 헥사값로 변환되어 입력된다.

    각 헥사값은 8비트로 8개의 픽셀이 왼쪽에서 오른쪽으로 변환되어 구성된다. (가장 왼쪽 비트 값은 1이고 맨 오른쪽 비트값은 128이다.) 이 헥사값은 0xdd형식으로 입력이 되며 여기서 d는 { 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f }중 하나이다.

    예시 : 8 픽셀의 WBBBBWWB는 0x9e로 쓰인다.
    (2+4+8+16+128 = 158 = 0x9e) 각 헥사값은 콤마(,)로 구분된다.
  • 마지막 줄은 "};"가 입력된다.

출력

처음 정수 n (8 <= n <= 512)을 출력하고, B와 W그리고 Q로 정확하게 쿼드트리 구조로 사진을 암호화하여 출력한다.

예제 입력 1

#define quadtree_width 16
#define quadtree_height 16
static char quadtree_bits[] = {
0xf0,0xf0,
0xf0,0xf0,
0xf0,0xf0,
0xf0,0xf0,
0x0f,0x0f,
0x0f,0x0f,
0x0f,0x0f,
0x0f,0x0f,
0xf0,0xf0,
0xf0,0xf0,
0xf0,0xf0,
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