D. Vasya And The Matrix

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Copy
  1. 2 3
    2 9
    5 3 13
Output

Copy
  1. YES
    3 4 5
    6 7 8
Input

Copy
  1. 3 3
    1 7 6
    2 15 12

Output

Copy
  1. NO

题目大意:a[i] 表示第i行的异或和,b[j] 表示第j列的异或和,然后给出a[i] 和 b[j],存在这样的矩阵就构造出任意一个,不存在就NO

对于我这种位运算知识为0的来说,再简单也不会。后来看了聚聚们说这道题很水,我看了看题解。首先存在条件:因为 a[i]是所有行的异或和 b[i]是所有列的异或和  ,都是所有元素异或和,应该相等,x ^ x = 0; 然后就控制每一行每一列,这里有一个性质:假如有f[i][j], 那么可以把它变为0, f[0][j] ^ f[i][0] ^ f[i][j] , 行和列的异或不变。

即  f[i][0] ^ f[0][j] = f[i][0] ^ f[0][j] ^ f[i][j]

所以转化为一行和一列即可。第一行第一列的数 是重点。a[0] = b[1] ^ b[2] ^ b[m]

所以 b[1] = b[2] ^ b[3] ^ ... b[m]  ^ a[0]    (1 ^ 2 = 3) -- >  (2 ^ 3 = 1)

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <string>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <algorithm>
  12. #include <sstream>
  13. #include <stack>
  14. using namespace std;
  15. typedef long long ll;
  16. const int inf = 0x3f3f3f3f;
  17. const int N = + ;
  18. int a[N], b[N];
  19.  
  20. int main() {
  21. //freopen("in.txt", "r", stdin);
  22. int n, m;
  23. scanf("%d%d", &n, &m);
  24. int cur = ;
  25. for(int i = ; i < n; i++) {
  26. scanf("%d", &a[i]);
  27. cur ^= a[i];
  28. }
  29. for(int i = ; i < m; i++) {
  30. scanf("%d", &b[i]);
  31. cur ^= b[i];
  32. }
  33. if(cur != ) {//因为 a[i]是所有行的异或和 b[i]是所有列的异或和
  34. printf("NO\n");// 都是所有元素异或和,应该相等,x ^ x = 0;
  35. return ;
  36. }
  37. printf("YES\n");
  38. for(int i = ; i < m; i++)//求第一行第一列 ****重点*****
  39. cur ^= b[i];
  40. cur ^= a[];
  41. printf("%d ", cur);
  42. for(int i = ; i < m; i++) {//第一行
  43. printf("%d ", b[i]);
  44. }
  45. printf("\n");
  46. for(int i = ; i < n; i++) {//每一行第一列和剩余的
  47. printf("%d ", a[i]);
  48. for(int j = ; j < m; j++)
  49. printf("0 ");
  50. printf("\n");
  51. }
  52. }

Educational Codeforces Round 48 (Rated for Div. 2) D 1016D Vasya And The Matrix (构造)的更多相关文章

  1. 【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix

    [链接] 我是链接,点我呀:) [题意] 告诉你每一行.每一列的异或和. 让你求出一个符合要求的原矩阵. [题解] 显然应该有 a1^a2^....^an = b1^b2^....^bn 也即两边同时 ...

  2. 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...

  3. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

  4. Educational Codeforces Round 48 (Rated for Div. 2)

    http://codeforces.com/contest/1016 A. 没想到这个也会TLE,太粗心了 B. 暴力就好了,多情况讨论又出错... 思路跟我一样的解法   为什么我做了那么多讨论,原 ...

  5. Educational Codeforces Round 48 (Rated for Div. 2) B 1016B Segment Occurrences (前缀和)

    B. Segment Occurrences time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  6. Educational Codeforces Round 48 (Rated for Div. 2)异或思维

    题:https://codeforces.com/contest/1016/problem/D 题意:有一个 n * m 的矩阵, 现在给你 n 个数, 第 i 个数 a[ i ] 代表 i 这一行所 ...

  7. Educational Codeforces Round 48 (Rated for Div. 2)——A. Death Note ##

    A. Death Note time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  8. Educational Codeforces Round 48 (Rated for Div. 2)G. Appropriate Team

    题意:求满足条件的(i,j)对数:\(gcd(v,a_i)=x,lcm(v,a_j)=y\) 题解:\(x|a_i,a_j|y\),\(x|y\),考虑质因子p,假设a_i中p次数为a,x中次数为b, ...

  9. 【Educational Codeforces Round 53 (Rated for Div. 2) C】Vasya and Robot

    [链接] 我是链接,点我呀:) [题意] [题解] 如果|x|+|y|>n 显然.从(0,0)根本就没法到(x,y) 但|x|+|y|<=n还不一定就能到达(x,y) 注意到,你每走一步路 ...

随机推荐

  1. (转)使用CUnit进行单元测试和覆盖率统计

    CUnit安装 如果能联网的话,直接 yum install CUnit-devel.x86_64 就完成安装了,注意要安装devel版本,这样才能找到头文件. 编写单元测试代码 CUnit的测试是单 ...

  2. 关于avpicture_fill 和 sws_scale的关系

    avpicture_fill((AVPicture *) pFrameRGB, buffer, PIX_FMT_RGB565, pCodecCtx->width, pCodecCtx->h ...

  3. 分立元件封装尺寸及PCB板材工艺与设计实例

    分立元件封装尺寸 inch mm (L)mm (w)mm (t)mm (a)mm (b)mm 0201 0603 0.6±0.05 0.30±0.05 0.23±0.05 0.10±0.05 0.60 ...

  4. photonView 空指针异常

    1.OBJ上要有PhotonView 脚本 2.PhotonNetwork.Instantiate方法初始化出来OBJ OBJ 预制体要放在Resources文件夹下 PhotonNetwork.In ...

  5. 服务注册选型比较:Consul vs Zookeeper vs Etcd vs Eureka

    zookeeper基于paxos的化简版zab,etcd基于raft算法.consul也是基于raft算法.etcd和consul作为后起之秀,并没有因为已经有了zookeeper而放弃自己,而是采用 ...

  6. redis源码笔记 - redis-cli.c

    这份代码是redis的client接口,其和server端的交互使用了deps目录下的hiredis c库,同时,在这部分代码中,应用了linenoise库完成类似history命令查询.自动补全等终 ...

  7. HDOJ1171(多重背包)

    #include<iostream> #include<cstdio> using namespace std; #define MAX(a,b) (a>b)?a:b + ...

  8. GCC提供的几个內建函数

    参考 https://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Other-Builtins.html#Other-Builtins https://en.wikipe ...

  9. 【转载】ruby 中数组函数示例(1)(转)

    函数名称 说明 示例 &      数组与,返回两数组的交集 [1,2] & [2,3] =>[2]   * 复制数组n次 [1,2]*2       => [1,2,1, ...

  10. [51nod1270] 数组的最大代价(简单dp)

    解题关键:先由贪心的思想得出任何一个位置只能取1或者a[i],然后dp即可. #include<bits/stdc++.h> using namespace std; typedef lo ...