#P6518. [CEOI 2010] arithmetic (day1)

[CEOI 2010] arithmetic (day1)

Description

You are given an R×CR \times C matrix. Some cells are already filled with numbers, and some cells are empty, represented by ..

You need to find a way to fill in the matrix so that the sequence formed by the numbers in each row (in order) and each column (in order) is an arithmetic progression.

Input Format

The first line contains two integers R,CR, C, representing the number of rows and columns of the matrix.

The next RR lines each contain CC numbers or characters: . or a number.

Output Format

Output RR lines in total, each containing CC integers or fractions, representing the completed matrix.

The fraction format is N/D, where NN and DD are coprime integers. If D=1D = 1, omit /D.

If no solution exists, output No solution.

All numbers in the output do not exceed 2020 digits.

Note: The testdata guarantees that all input numbers are integers, but the output may contain real numbers, which must be represented as fractions. There may be multiple valid solutions; output any one. This problem uses SPJ.

3 5
. . 3 . 5
. . . 5 .
. . . . 7
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
1 6
4 . . 0 . 
4 8/3 4/3 0 -4/3 -8/3
1 4
1 2 . 2
No solution.
3 3
1 . .
. 2 .
. . 3
1 2 3
1 2 3
1 2 3

Hint

Sample Explanation

Sample 1 Explanation

We can first fill in 66 at row 2, column 5, then fill in the first row and the second row, and finally fill in the first column and the fourth column.

Sample 4 Hint

The output is one of multiple possible solutions.

Constraints

This problem uses bundled testdata.

The testdata is divided into the following 1010 subtasks, each worth 1010 points.

Subtask ID Limit
11 All numbers are already filled in.
22 R=1R = 1 or C=1C = 1
33 R=C=2R = C = 2
44 The solution is guaranteed to be unique, and the method used in Sample 1 can be applied.
55 The solution is guaranteed to be unique, and the answer contains only integers.
66 The solution is guaranteed to be unique.
77 Each test case can only have either a unique solution that contains only integers, or no solution.
88 Each test case has only a unique solution, or no solution.
99 No special restrictions.
1010
  • In subtasks 191 \sim 9, it is guaranteed that 1R,C61 \le R, C \le 6.
  • For all test points, it is guaranteed that 1R,C501 \leq R, C \leq 50, and all given numbers in the matrix are between 100100-100 \sim 100.

Notes

This problem is translated from CEOI 2010 day 1 T2 arithmetic.

The translation copyright belongs to the problem provider

https://www.luogu.com.cn/user/45475

The SPJ is provided by @一扶苏一. Special thanks.

Translated by ChatGPT 5