RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00094

Slikar

스페셜 저지 — 출력을 사용자 정의 프로그램으로 검사하므로 여러 정답이 인정될 수 있습니다.
Gold II 골드 II
난이도
1s
시간 제한
32MB
메모리 제한
1
맞았습니다!!
5
제출 수
20.0%
정답률
레이팅

의견: 0

설명

Josip is a strange painter. He wants to paint a picture consisting of \(N \times N\) pixels, where \(N\) is a power of two (\(1, 2, 4, 8, 16\) etc.). Each pixel will be either black or white. Josip already has an idea of how each pixel will be coloured.

This would be no problem if Josip's painting process wasn't strange. He uses the following recursive process:

  • If the picture is a single pixel, he colours it the way he intended.
  • Otherwise, split the square into four smaller squares and then:
    1. Select one of the four squares and colour it white.
    2. Select one of the three remaining squares and colour it black.
    3. Consider the two remaining squares as new paintings and use the same three-step process on them.

Soon he noticed that it was not possible to convert all his visions to paintings with this process. Your task is to write a program that will paint a picture that differs as little as possible from the desired picture. The difference between two pictures is the number of pairs of pixels in corresponding positions that differ in colour.

제약

In test cases worth 50% points, N will be at most 8.
Contest #4, \(17^{th}\) January 2009

입력 형식

The first line contains an integer \(N\) (\(1 \le N \le 512\)), the size of the picture Josip would like to paint. \(N\) will be a power of \(2\).

Each of the following \(N\) lines contains \(N\) digits \(0\) or \(1\), white and black squares in the target picture.

출력 형식

On the first line, output the smallest possible difference that can be achieved.

On the next \(N\) lines, output a picture that can be painted with Josip's process and achieves the smallest difference. The picture should be in the same format as in the input.

Note: The second part of the output (the picture) may not be unique. Any correct output will be accepted.

Scoring: In test cases worth \(50\%\) of points, \(N\) will be at most \(8\).

서브태스크
서브태스크점수설명

Subtask 1

50점

\(N \le 8\)

Subtask 2

50점

No additional constraints (\(N \le 512\)).

예제 1
입력
4
0001
0001
0011
1110
출력
1
0001
0001
0011
1111
예제 2
입력
4
1111
1111
1111
1111
출력
6
0011
0011
0111
1101
예제 3
입력
8
01010001
10100011
01010111
10101111
01010111
10100011
01010001
10100000
출력
16
00000001
00000011
00000111
00001111
11110111
11110011
11110001
11110000
문제 정보

riseoj 작성

출처 COCI 2008/2009 Contest 4

태그

평가 및 의견

Slikar

개요
출제자 난이도 Gold II 골드 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Slikar

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8