CF509D.Restoring Numbers
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vasya had two arrays consisting of non-negative integers: a of size n and b of size m. Vasya chose a positive integer k and created an n × m matrix v using the following formula:

Vasya wrote down matrix v on a piece of paper and put it in the table.
A year later Vasya was cleaning his table when he found a piece of paper containing an n × m matrix w. He remembered making a matrix one day by the rules given above but he was not sure if he had found the paper with the matrix v from those days. Your task is to find out if the matrix w that you've found could have been obtained by following these rules and if it could, then for what numbers k, _a_1, _a_2, ..., a__n, _b_1, _b_2, ..., b__m it is possible.
瓦西娅有两个由非负整数组成的数组:长度为 n 的数组 a 和长度为 m 的数组 b。瓦西娅选择了一个正整数 k,并按如下公式构造了一个 n×m 矩阵 v:

瓦西娅将矩阵 v 写在一张纸上,并将其放在了桌面上。
一年后,瓦西娅整理桌面时发现了一张写有 n×m 矩阵 w 的纸。他记得某天曾按上述规则构造过一个矩阵,但不确定这张纸是否就是当年所写的矩阵 v。你的任务是判断:所发现的矩阵 w 是否可能通过上述规则得到;若可能,则需找出所有满足条件的正整数 k 以及非负整数 a1,a2,…,an,b1,b2,…,bm。
输入格式
The first line contains integers n and m (1 ≤ n, m ≤ 100), separated by a space — the number of rows and columns in the found matrix, respectively.
The i-th of the following lines contains numbers w__i, 1, w__i, 2, ..., w__i, m (0 ≤ w__i, j ≤ 109), separated by spaces — the elements of the i-th row of matrix w.
第一行包含两个整数 n 和 m(1≤n,m≤100),以空格分隔——分别表示所给矩阵的行数和列数。
接下来的第 i 行包含 m 个数字 wi,1, wi,2, …, wi,m(0≤wi,j≤109),以空格分隔——表示矩阵 w 的第 i 行的元素。
输出格式
If the matrix w could not have been obtained in the manner described above, print "NO" (without quotes) in the single line of output.
Otherwise, print four lines.
In the first line print "YES" (without quotes).
In the second line print an integer k (1 ≤ k ≤ 1018). Note that each element of table w should be in range between 0 and k - 1 inclusively.
In the third line print n integers _a_1, _a_2, ..., a__n (0 ≤ a__i ≤ 1018), separated by spaces.
In the fourth line print m integers _b_1, _b_2, ..., b__m (0 ≤ b__i ≤ 1018), separated by spaces.
如果矩阵 w 无法通过上述方式得到,则在输出的单独一行中打印 “NO”(不带引号)。
否则,打印四行:
第一行打印 “YES”(不带引号);
第二行打印一个整数 k(1≤k≤1018)。注意:表格 w 中每个元素都必须在 0 到 k−1(含端点)的范围内;
第三行打印 n 个整数 a1,a2,…,an(0≤ai≤1018),以空格分隔;
第四行打印 m 个整数 b1,b2,…,bm(0≤bi≤1018),以空格分隔。
输入输出样例
输入#1
2 3 1 2 3 2 3 4
输出#1
YES 1000000007 0 1 1 2 3
输入#2
2 2 1 2 2 0
输出#2
YES 3 0 1 1 2
输入#3
2 2 1 2 2 1
输出#3
NO
说明/提示
By
we denote the remainder of integer division of b by c.
It is guaranteed that if there exists some set of numbers k, _a_1, ..., a__n, _b_1, ..., b__m, that you could use to make matrix w, then there also exists a set of numbers that meets the limits 1 ≤ k ≤ 1018, 1 ≤ a__i ≤ 1018, 1 ≤ b__i ≤ 1018 in the output format. In other words, these upper bounds are introduced only for checking convenience purposes.
我们用
表示整数 $ b $ 除以 $ c $ 所得的余数。
题目保证:若存在某组数 $ k,,a_1,,\dots,,a_n,,b_1,,\dots,,b_m $ 可用于构造矩阵 $ w $,则必然也存在一组满足输出格式限制 $ 1\leq k\leq 10^{18} 、 1\leq a_i\leq 10^{18} 、 1\leq b_i\leq 10^{18} $ 的数。换言之,这些上界仅出于检验便利性而引入。
输入解题思路,AI测评打分。不知道怎么写?