CodeForces 486B

Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner:

where is equal to 1 if some ai = 1, otherwise it is equal to 0.

Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:

.

(Bij is OR of all elements in row i and column j of matrix A)

Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large.

Input

The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively.

The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1).

Output

In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one.

Sample Input

Input
2 2
1 0
0 0
Output
NO
Input
2 3
1 1 1
1 1 1
Output
YES
1 1 1
1 1 1
Input
2 3
0 1 0
1 1 1
Output
YES
0 0 0
0 1 0
第一次看题目把a,b两个数组看反了,我觉得这道题还是挺好写的,反这写就好了,只要判断a数组当行列上有1的时候对应的b数组是否为1,首先要把a数组复制出来
b数组中为0是,a数组对应的行列都要为0;
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 using namespace std;
 6 int a[200][200];
 7 int m,n;
 8 void fun(int x,int y)
 9 {
10     for(int i=1;i<=m;i++)
11         a[i][y]=0;
12     for(int j=1;j<=n;j++)
13         a[x][j]=0;
14 }
15 int main()
16 {
17     int x[105],y[105];
18     int b[200][200];
19     int i,j;
20     cin>>m>>n;
21     for(i=1;i<=m;i++)
22     {
23         for(j=1;j<=n;j++)
24             a[i][j]=1;
25     }
26     memset(x,0,sizeof(x));
27     memset(y,0,sizeof(y));
28     for(i=1;i<=m;i++)
29     {
30         for(j=1;j<=n;j++)
31         {
32             cin>>b[i][j];
33             if(b[i][j]==0)
34                 fun(i,j);
35         }
36     }
37     /*for(i=1;i<=m;i++)
38     {
39         for(j=1;j<=n;j++)
40             cout<<a[i][j]<<" ";
41         cout<<endl;
42     }*/
43     for(i=1;i<=m;i++)
44     {
45         for(j=1;j<=n;j++)
46         {
47             if(a[i][j]==1)
48             {
49                 x[i]=1;
50                 y[j]=1;
51             }
52         }
53     }
54     /*cout<<x[1]<<" "<<x[2]<<endl;
55     cout<<y[1]<<" "<<y[2]<<endl;*/
56     int flag=0;
57     for(i=1;i<=m;i++)
58     {
59         for(j=1;j<=n;j++)
60         {
61             if(x[i]==1||y[j]==1)
62             {
63                 if(b[i][j]==1)
64                     flag=1;
65                 else
66                 {
67                     cout<<"NO"<<endl;
68                     return 0;
69                 }
70             }
71             else
72             {
73                 if(b[i][j]==1)
74                 {
75                     cout<<"NO"<<endl;
76                     return 0;
77                 }
78                 else
79                     flag=1;
80             }
81         }
82     }
83     if(flag==1)
84         cout<<"YES"<<endl;
85     for(i=1;i<=m;i++)
86     {
87         for(j=1;j<n;j++)
88             cout<<a[i][j]<<" ";
89         cout<<a[i][n]<<endl;
90     }
91     return 0;
92 }
原文地址:https://www.cnblogs.com/Aa1039510121/p/5697077.html