Magic Rectangle
Time limit1sMemory limit1024 MB
Fill the erased entries of the given integer grid, using rational values, so every row and column is an arithmetic sequence, or print ej magisk if impossible.
- Level
Medium7 of 10
- Topics
- Math, Implementation, Matrix
- Solved
- No attempts yet
Problem
A magic sequence of length is a sequence of the form , where and are rational numbers. For example, , , and are magic sequences.
A magic rectangle of size is a rectangle in which every row and every column is a magic sequence.
Given a rectangle of integers with some numbers erased, determine whether the erased numbers can be filled in so that the rectangle is a magic rectangle.
Input
The first line of the input contains and , the number of rows and columns in the given rectangle. The next lines each contain integers.
An erased number is represented by a period (.).
Output
If no solution exists, print ej magisk.
Otherwise, print lines, each containing numbers: a magic rectangle obtained by replacing the erased numbers in the input rectangle.
Rational numbers must be written in the form N/D, where and are each at most 100 digits long. There must be no spaces between the numbers and the division sign. If , you may write N.
Constraints
In the first 9 test cases, .