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 21 00 0

Output

NO

Input

2 31 1 11 1 1

Output

YES1 1 11 1 1

Input

2 30 1 01 1 1

Output

YES0 0 00 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 }
时间: 2024-09-28 15:39:22

CodeForces 486B的相关文章

Codeforces 486B - OR in Matrix

矩阵的 OR ,也是醉了. 题目意思很简单,就是问你有没有这么一个矩阵,可以变化,得到输入的矩阵. 要求是这个矩阵每行都可以上下任意移动,每列都可以左右任意移动. 解题方法: 1.也是导致我WA 的原因,首先要判断是否是一个零矩阵,如果是一个零矩阵,那么YES输出 2.判断输入矩阵存在1的那个位置,在输出矩阵的同一行同一列是否存在1,如果没有则NO输出 3.开辟数组X[MAXN],Y[MAXN]记录这一行或者这一列是否有0这个元素 //#pragma comment(linker, "/STAC

【codeforces】Codeforces Round #277 (Div. 2) 解读

门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include <cstring> #include <algorithm> using namespace std ; typedef long long LL ; LL n ; int main () { while ( ~scanf ( "%I64d" , &n )

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th

Codeforces Round #286 (Div. 1) A. Mr. Kitayuta, the Treasure Hunter DP

链接: http://codeforces.com/problemset/problem/506/A 题意: 给出30000个岛,有n个宝石分布在上面,第一步到d位置,每次走的距离与上一步的差距不大于1,问走完一路最多捡到多少块宝石. 题解: 容易想到DP,dp[i][j]表示到达 i 处,现在步长为 j 时最多收集到的财富,转移也不难,cnt[i]表示 i 处的财富. dp[i+step-1] = max(dp[i+step-1],dp[i][j]+cnt[i+step+1]) dp[i+st

Codeforces 772A Voltage Keepsake - 二分答案

You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power store

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp

Codeforces Round #408 (Div. 2) B

Description Zane the wizard is going to perform a magic show shuffling the cups. There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the table at the position x?=?i. The probl