eolymp
bolt
Try our new interface for solving problems
Məsələlər

An Arithmetic Rectangle

An Arithmetic Rectangle

After the lesson on arithmetic progressions, the teacher gave Peter homework: a sheet of paper with numbers written in some cells of a \textbf{R}×\textbf{C} grid. Some of the cells were empty. Peter's task is to create an arithmetic rectangle by filling in the missing numbers. In an arithmetic rectangle, all the numbers in each row and in each column have to form an arithmetic progression in the order in which they appear. For example, this is a arithmetic rectangle: 1 3 5 7 9 2 2 2 2 2 3 1 -1 -3 -5 Peter is lazy to do such tasks manually. He wants you to write a program that will do it for him. You are given a grid of \textbf{integers}, some of them substituted by dots. Find out whether it is possible to replace the dots by some \textbf{rational} numbers in order to obtain an arithmetic rectangle. If there is a solution, find one. \textit{\textbf{Note}}: An arithmetic progression is a sequence of numbers such that the difference of any two successive elements of the sequence is a constant. \InputFile The first line of the input contains two positive integers \textbf{R} and \textbf{C}: the dimensions of the grid. \textbf{R} lines follow, each of them containing \textbf{C} tokens separated by single spaces. Each of the tokens is either a dot (\textbf{.}), or an integer. \textbf{Constraints} Each number given in the grid is between \textbf{-100} and \textbf{100}, inclusive. There are \textbf{10} batches of test cases, worth \textbf{10}points each. In batches \textbf{1} through \textbf{9} we have \textbf{1} ≤ \textbf{R}, \textbf{C} ≤ \textbf{6}. The properties of the individual batches are given below. \begin{itemize} \item \textbf{Batch 1}. All numbers are already filled in. \item \textbf{Batch 2}. Either \textbf{R = 1} or \textbf{C = 1} in each test case. \item \textbf{Batch 3}. \textbf{R = C = 2} in each test case. \item \textbf{Batch 4}. Each test case has a unique solution that can be found using the approach suggested in the first example. \item \textbf{Batch 5}. Each test case has a unique solution, and the solution contains integers only. \item \textbf{Batch 6}. Each test case has a unique solution. \item \textbf{Batch 7}. Each test case either has a unique solution that contains integers only, or has no solution at all. \item \textbf{Batch 8}. Each test case either has a unique solution, or has no solution at all. \item \textbf{Batch 9}. Arbitrary test cases. \item \textbf{Batch 10}. Arbitrary test cases with \textbf{1} ≤ \textbf{R}, \textbf{C} ≤ \textbf{50}. \end{itemize} \OutputFile If there is no solution, output a single line with the string "\textbf{No solution.}" (quotes for clarity). If there are multiple solutions, pick and output any single solution. When outputting a solution, output \textbf{R} rows, each with \textbf{C} space-separated rational numbers. Each rational number shall be printed as "\textbf{N/D}", where \textbf{D} is positive and \textbf{N} and \textbf{D} are relatively prime. If \textbf{D} is \textbf{1}, omit the "\textbf{/D}" part. No number in your output may have more than 20 digits. (It should be easy to satisfy this restriction, its only intent is to simplify checking your outputs.)
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
3 5
. . 3 . 5
. . . 5 .
. . . . 7
Çıxış verilənləri #1
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
Müəllif Michal Forišek