Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <set>
- #include <cmath>
- #include <map>
- using namespace std;
- typedef long long ll;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int n, m;
- cin >> n >> m;
- vector<vector<int>> a(n, vector<int>(m, 1));
- vector<vector<int>> b(n, vector<int>(m));
- vector<vector<int>> c(n, vector<int>(m));
- bool flag = true;
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < m; ++j) {
- cin >> b[i][j];
- if (!b[i][j])
- a[i][j] = 0;
- }
- }
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < m; ++j) {
- cin >> c[i][j];
- if (!c[i][j])
- a[i][j] = 0;
- }
- }
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < m; ++j) {
- bool found = false;
- for (int u = i; u > -1; --u) {
- for (int v = j; v > -1; --v) {
- if (a[u][v]) {
- found = true;
- }
- }
- }
- if (found != b[i][j]) {
- flag = false;
- }
- }
- }
- for (int i = n - 1; i > -1; --i) {
- for (int j = n - 1; j > -1; --j) {
- bool found = false;
- for (int u = i; u < n; ++u) {
- for (int v = j; v < m; ++v) {
- if (a[u][v])
- found = true;
- }
- }
- if (found != c[i][j])
- flag = false;
- }
- }
- if (flag) {
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < m; ++j) {
- cout << a[i][j] << " ";
- }
- cout << "\n";
- }
- }
- else
- cout << "-1\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement