XCopy
시간 제한2초메모리 제한1024 MB
N 곱하기 M 격자의 각 칸에 서로 다른 정수를 배정하되 이웃한 칸끼리 정확히 한 비트만 다르고 최댓값이 최소가 되도록 한다.
문제
Today, at the end of the programming class, the teacher gave very difficult homework, so the children decided to cheat and copy it from one another. However, they have to work smart in order to not get caught cheating.
The class has students, placed in benches on rows and columns. Two children are considered neighbours if one sits in a bench adjacent to the left, the right, above or below the bench in which the other one sits. The homework consists of finding a certain non-negative integer. In order for them to not get caught cheating, all these integers must be different. Also, the children are very lazy, therefore they will barely modify their answers when copying them from their neighbours. More precisely, each child’s answer differs by exactly one bit in base compared to any of his neighbours’ answers. For example and differ in exactly one bit, whereas and do not.
The children don’t want to raise suspicion, therefore they want the largest answer that any of them gave to be as small as possible. Given and , create a configuration of answers so that the teacher won’t find out the children cheated.
입력
The input consists of and on a single line, separated by a single space.
출력
The output consists of the optimal answers for the children. The output should have rows, each containing non-negative integers separated by a single space. These represent the answers for the children, according to where they sit in the class.
제한
힌트
Within this section, a subscript after a number represents the base in which the number is written. For instance eight may be written as .
One set of optimal answers for the students are given in the following table:
Observe that between any two adjacent benches the numbers differ with exactly one bit. The maximum value of the solution is , which is the optimal answer. Clearly other solutions are optimal – such as the previous solution but flipped vertically or horizontally.
Another possible partial solution in which the maximum is is:
This solution would be scored, according to the scoring formula, with of the test case score.