zoukankan      html  css  js  c++  java
  • cf 1016D

    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
    2 3
    2 9
    5 3 13
    output
    Copy
    YES
    3 4 5
    6 7 8
    input
    Copy
    3 3
    1 7 6
    2 15 12
    output
    Copy
    NO




     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cstdlib>
     5 #include <cstring>
     6 #include <string>
     7 #include <deque>
     8 using namespace std;
     9 #define ll long long 
    10 #define  N 109
    11 #define  gep(i,a,b)     for(int  i=a;i<=b;i++)
    12 #define  gepp(i,a,b)   for(int  i=a;i>=b;i--)
    13 #define  gep1(i,a,b)   for(ll i=a;i<=b;i++)
    14 #define  gepp1(i,a,b)  for(ll i=a;i>=b;i--)    
    15 #define  mem(a,b)  memset(a,b,sizeof(a))
    16 int n,m;
    17 int a[N],b[N],c[N][N];
    18 int main()
    19 {
    20     scanf("%d%d",&n,&m);
    21     int  x=0,y=0;
    22     gep(i,1,n) {
    23     scanf("%d",&a[i]);
    24     x^=a[i];
    25     } 
    26     gep(j,1,m){
    27         scanf("%d",&b[j]);
    28         y^=b[j];
    29     }
    30     if(x!=y){
    31         printf("NO
    ");
    32         return 0;
    33     }
    34     x^=a[1];x^=b[1];
    35     c[1][1]=x;
    36     gep(i,2,n){
    37         c[i][1]=a[i];
    38     }
    39     gep(j,2,m){
    40         c[1][j]=b[j];
    41     }
    42     printf("YES
    ");
    43     gep(i,1,n){
    44         gep(j,1,m){
    45             printf("%d%c",c[i][j],j==m?'
    ':' ');
    46         }
    47     }
    48     return 0;
    49 }
  • 相关阅读:
    撩妹技能 get,教你用 canvas 画一场流星雨
    git详细使用教程入门到精通(史上最全的git教程)
    Google Performance工具,你还不会用?Git走起。
    使用PIE.htc让万恶的IE内核浏览器IE678支持CSS3部分属性
    HTML编码规范
    Canvas制作的下雨动画
    Flex 布局教程:语法和实例
    CSS编码规范
    奇葩程序写的神一样的注释,被老板看见会不会开出呢?
    Vertical-Align你应该知道的一切
  • 原文地址:https://www.cnblogs.com/tingtin/p/9487287.html
Copyright © 2011-2022 走看看