CF1016D Vasya And The Matrix

若所有行异或起来不等于所有列异或起来,显然无解

否则, 一定可以得到一个合法的矩阵:

将左上角\((n-1)* (m-1)\)置为0,右下角的 L 形的两条边的每个值就是给定的值,(n,m) 的值可以通过计算得到

#include<bits/stdc++.h>
using namespace std;
const int N=2e3+11;
int n,m;
int l[N],h[N];
int a[N][N];
inline int read()
{
	int s=0;
	char ch=getchar();
	while(ch>'9'||ch<'0') ch=getchar();
	while(ch>='0'&&ch<='9')
	{
		s=(s<<1)+(s<<3)+(ch^48);
		ch=getchar();
	}
	return s;
}
int main()
{
	n=read();
	m=read();
	int sumh=0,suml=0;
	for(int i=1;i<=n;++i) h[i]=read(),sumh^=h[i];
	for(int i=1;i<=m;++i) l[i]=read(),suml^=l[i];
	if(sumh!=suml) {cout<<"NO"<<endl;return 0;}
	sumh=0;
	for(int i=1;i<n;++i) a[i][m]=h[i],sumh^=h[i];
	for(int i=1;i<m;++i) a[n][i]=l[i];
	a[n][m]=l[m]^sumh;
	cout<<"YES"<<endl;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j) cout<<a[i][j]<<" ";
		cout<<endl;
	}
	return 0;
}
posted @ 2021-11-04 20:09  sitiy  阅读(29)  评论(0编辑  收藏  举报