Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!

Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.

Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.

Input

The first line contains two numbers n and m (2 ≤ n, m ≤ 100) — the dimensions of the matrix.

The second line contains n numbers a1, a2, ..., an (0 ≤ ai ≤ 109), where ai is the xor of all elements in row i.

The third line contains m numbers b1, b2, ..., bm (0 ≤ bi ≤ 109), where bi is the xor of all elements in column i.

Output

If there is no matrix satisfying the given constraints in the first line, output "NO".

Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cim (0 ≤ cij ≤ 2·109) — the description of the matrix.

If there are several suitable matrices, it is allowed to print any of them.

Examples

Input
2 3
2 9
5 3 13
Output
YES
3 4 5
6 7 8
Input
3 3
1 7 6
2 15 12
Output
NO

题意:
有一个n*m的矩阵,每一个方格中有一个数。
现在给你 两组数
第一组,有n 个数 每一个数i代表 第i行的所有数异或起来的数值。
第二组,有m 个数 每一个数j代表 第j列的所有数异或起来的数值。
问你是否存在一个矩阵,使之满足上面的条件,如果存在,请输出任意一个。 思路:
很好的一个构造题,
我们来看上图的情况,ai代表是列的异或值,bi代表是那一列的异或值。
那么
a1=x1^x4
a2=x2^x5
a3=x3^x6 b1=x1^x2^x3
b2=x4^x5^x6 a1^a2^a3=x1^x2^x3^x4^x5^x6
b1^b2=x1^x2^x3^x4^x5^x6 所以我们看数组a和数组b的分别异或起来的值是否相等,如果相等就存在答案,反而反之。 我们再来看如何构造出答案数组,
我们可以以一下的方式构造最为简单,
把最后一行赋值为a[i] ,最后一列赋值为b[j] ,其他全赋值为0(因为0异或任意值x等于x)
,然后最右下角的数x赋值为 a1^a2^a3....^a(m-1) ^ bn
根据异或的性质就可以推算出 这个x就既满足行又满足列的关系。
例如行上, x ^ (a1~a m-1 ) = bn , 然后按照这个方法实现code就可以了,细节见代码。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll a[maxn];
ll b[maxn];
ll ans[][];
int main()
{
//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
ll n,m;
cin>>n>>m;
ll t1=0ll;
ll t2=0ll;
repd(i,,n)
{
cin>>a[i];
t1^=a[i];
}
repd(i,,m)
{
cin>>b[i];
t2^=b[i];
}
if(t1!=t2)
{
cout<<"NO"<<endl;
}else
{
repd(i,,n)
{
ans[i][m]^=a[i];
}
repd(j,,m)
{
ans[n][j]^=b[j];
}
t2^=b[m];
t2^=a[n];
ans[n][m]=t2;
cout<<"YES"<<endl;
repd(i,,n)
{
repd(j,,m)
{
cout<<ans[i][j]<<" ";
}
cout<<endl;
} } return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}

Vasya And The Matrix CodeForces - 1016D (思维+构造)的更多相关文章

  1. Sonya and Matrix CodeForces - 1004D (数学,构造)

    http://codeforces.com/contest/1004/problem/D 题意:网格图给定到中心点的曼哈顿距离数组, 求该图n,m及中心点位置 首先可以观察到距离最大值mx一定在某个角 ...

  2. A Mist of Florescence CodeForces - 989C(思维构造)

    题意: 让你构造一个图,使得A,B,C,D的个数为给定的个数,上下左右连通的算一个. 哎呀 看看代码就懂了..emm..很好懂的 #include <bits/stdc++.h> usin ...

  3. Vasya and Magic Matrix CodeForces - 1042E (概率dp)

    大意:给定n*m矩阵, 初始位置(r,c), 每一步随机移动到权值小于当前点的位置, 得分为移动距离的平方, 求得分期望. 直接暴力dp的话复杂度是O(n^4), 把距离平方拆开化简一下, 可以O(n ...

  4. Educational Codeforces Round 48 (Rated for Div. 2) D 1016D Vasya And The Matrix (构造)

    D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  5. codeforces1016 D. Vasya And The Matrix(思维+神奇构造)

    D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. D. Vasya And The Matrix(Educational Codeforces Round 48)

    D. Vasya And The Matrix time limit per test2 seconds memory limit per test256 megabytes inputstandar ...

  7. CF 1042 E. Vasya and Magic Matrix

    E. Vasya and Magic Matrix http://codeforces.com/contest/1042/problem/E 题意: 一个n*m的矩阵,每个位置有一个元素,给定一个起点 ...

  8. Vasya and a Tree CodeForces - 1076E(线段树+dfs)

    I - Vasya and a Tree CodeForces - 1076E 其实参考完别人的思路,写完程序交上去,还是没理解啥意思..昨晚再仔细想了想.终于弄明白了(有可能不对 题意是有一棵树n个 ...

  9. hdu4671 思维构造

    pid=4671">http://acm.hdu.edu.cn/showproblem.php? pid=4671 Problem Description Makomuno has N ...

随机推荐

  1. Why 0.1 + 0.2 === 0.30000000000000004 ?

    Why 0.1 + 0.2 === 0.30000000000000004 ? 在浮点数运算中产生误差值的示例中,最出名应该是0.1 + 0.2 === 0.30000000000000004了,到底 ...

  2. SpringBoot 启动流程

    SpringBoot 启动流程 加载 resources/META-INF/spring.factories 中配置的 ApplicationContextInitializer 和 Applicat ...

  3. ControlTemplate in WPF —— ListBox

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x ...

  4. 使用jedis执行lua脚本

    转: redis学习(十五) 使用jedis执行lua脚本(实现一个对IP的限流) 2018年09月15日 20:07:26 码农-文若书生 阅读数:1609   使用jedis执行lua脚本(实现一 ...

  5. JavaScript中二进制与10进制互相转换

    webpack打包生成的代码中涉及了一些二进制位与的操作, 所以今天来学习一下JavaScript中的二进制与十进制转换操作吧 十进制转二进制: var num = 100 num.toString( ...

  6. 【Java基础】JAVA 使用线程的几种方式

    之前放在自己网站上的例子,因为网站关闭,已经找不到了,想用的时候,没有的话又重新翻书是很麻烦的事情.所以重新记录一下,以备将来查看. 第一种,让任务类继承Runable接口,然后将任务类对象放入Thr ...

  7. 前端深入之css篇丨2020年前,彻底掌握css动画

    马上就2020年了,不知道小伙伴们今年学习了css3动画了吗? 说起来css动画是一个很尬的事,一方面因为公司用css动画比较少,另一方面大部分开发者习惯了用JavaScript来做动画,所以就导致了 ...

  8. junction 文件夹做连接到别的分区

    加载连接 C:\>junction "C:\Docume~1\Admini~1\LocalS~1\Applic~1\360Chr~1\Chrome\UserDa~1\Default&q ...

  9. Angular5 *ngIf 和 hidden 的区别

    问题 项目中遇到一个问题,有一个过滤查询的面板,需要通过一个展开折叠的button,来控制它的show 和 hide.这个面板中,有一个Select 组件,一个 input 查询输入框. 原来代码是: ...

  10. pom文件中引入依赖成功了,但是jar包找不着

    编写代码的时候总是会碰到各种奇奇怪怪的问题,最近引入依赖的时候发现依赖虽然引入成功了,而且查看仓库,仓库中也存在该jar包,但是项目代码中并没有找到该jar包,重新导入reimport各种都试了还是不 ...