-
Notifications
You must be signed in to change notification settings - Fork 0
/
509D.cpp
52 lines (47 loc) · 1.38 KB
/
509D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Rodrigo Farias de Macêdo
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define SZ(S) ((int) ((S).size()))
#define DEBUG(x) { cout << #x << " = " << x << endl; }
#define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
#define PR0(a,n) { REP(_,n) cout << a[_] << ' '; cout << endl; }
ll n, m, mat[110][110], a[110], b[110];
ll gcd(ll a, ll b){ return b == 0 ? a : gcd(b, a%b);}
int main() {
scanf("%d %d", &n, &m);
REP(i, n){
REP(j, m) scanf("%d", &mat[i][j]);
}
a[0] = 0;
REP(i, m) b[i] = mat[0][i];
FOR(i, 1, n)a[i] = mat[i][0] - b[0];
ll mx = -1;
ll g = 0;
REP(i, n){
REP(j, m){
if(a[i]+b[j]-mat[i][j]!= 0){
g = gcd(g, abs(a[i]+b[j] - mat[i][j]));
}
mx = max(mx, mat[i][j]);
}
}
if(g <= mx && g!= 0) printf("NO\n");
else{
ll k;
if(g>mx){
k = g;
}else if(g==0){
k = mx+1;
}
printf("YES\n%d\n", k);
REP(i, n) if(a[i]<0) a[i] += k;
REP(i, m) if(b[i]<0) b[i] += k;
PR0(a, n); PR0(b, m);
}
return 0;
}