Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
int const N = 101;
int n, m, a[N], b[N];
int main() {
int cur = 0;
scanf("%d %d", &n, &m);
for(int i = 0; i < n; ++i)
scanf("%d", a + i), cur ^= a[i];
for(int i = 0; i < m; ++i)
scanf("%d", b + i), cur ^= b[i];
if(cur != 0) {
puts("NO");
return 0;
}
puts("YES");
for(int i = 1; i < m; ++i)
cur ^= b[i];
cur ^= a[0];
printf("%d ", cur);
for(int i = 1; i < m; ++i)
printf("%d ", b[i]);
puts("");
for(int i = 1; i < n; ++i) {
printf("%d ", a[i]);
for(int j = 1; j < m; ++j)
printf("0 ");
puts("");
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
2 3
2 9
5 3 13
2 9
5 3 13
Output
YES
3 4 5
6 7 8
3 4 5
6 7 8
Demonstration
Codeforces Solution-Vasya And The Matrix-Solution in C, C++, Java, Python,Codeforces Solution