Advertisement
deushiro

Untitled

Feb 2nd, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <set>
  5. #include <cmath>
  6. #include <map>
  7.  
  8.  
  9. using namespace std;
  10.  
  11. typedef long long ll;
  12.  
  13. int main()
  14. {
  15.     ios_base::sync_with_stdio(false);
  16.     cin.tie(0);
  17.     cout.tie(0);
  18.     int n, m;
  19.     cin >> n >> m;
  20.     vector<vector<int>> a(n, vector<int>(m, 1));
  21.     vector<vector<int>> b(n, vector<int>(m));
  22.     vector<vector<int>> c(n, vector<int>(m));
  23.     bool flag = true;
  24.     for (int i = 0; i < n; ++i) {
  25.         for (int j = 0; j < m; ++j) {
  26.             cin >> b[i][j];
  27.             if (!b[i][j])
  28.                 a[i][j] = 0;
  29.         }
  30.     }
  31.     for (int i = 0; i < n; ++i) {
  32.         for (int j = 0; j < m; ++j) {
  33.             cin >> c[i][j];
  34.             if (!c[i][j])
  35.                 a[i][j] = 0;
  36.         }
  37.     }
  38.     for (int i = 0; i < n; ++i) {
  39.         for (int j = 0; j < m; ++j) {
  40.             bool found = false;
  41.             for (int u = i; u > -1; --u) {
  42.                 for (int v = j; v > -1; --v) {
  43.                     if (a[u][v]) {
  44.                         found = true;
  45.                     }
  46.                 }
  47.             }
  48.             if (found != b[i][j]) {
  49.                 flag = false;
  50.             }
  51.         }
  52.     }
  53.     for (int i = n - 1; i > -1; --i) {
  54.         for (int j = n - 1; j > -1; --j) {
  55.             bool found = false;
  56.             for (int u = i; u < n; ++u) {
  57.                 for (int v = j; v < m; ++v) {
  58.                     if (a[u][v])
  59.                         found = true;
  60.                 }
  61.             }
  62.             if (found != c[i][j])
  63.                 flag = false;
  64.         }
  65.     }
  66.     if (flag) {
  67.         for (int i = 0; i < n; ++i) {
  68.             for (int j = 0; j < m; ++j) {
  69.                 cout << a[i][j] << " ";
  70.             }
  71.             cout << "\n";
  72.         }
  73.     }
  74.     else
  75.         cout << "-1\n";
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement