Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.34 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. const int N = 50 + 5;
  7.  
  8. int a[N][N];
  9. char r[N], c[N];
  10. bool rr[N], cc[N];
  11.  
  12. int main() {
  13.     scanf("%s%s", r, c);
  14.     int nr = strlen(r);
  15.     int nc = strlen(c);
  16.     for (int i = 0; i < nr; i++) {
  17.         rr[i] = r[i] - '0' != nc % 2;
  18.     }
  19.     for (int i = 0; i < nc; i++) {
  20.         cc[i] = c[i] - '0' != nr % 2;
  21.     }
  22.     for (int i = 0; i < nr; i++) {
  23.         for (int j = 0; j < nc; j++) {
  24.             a[i][j] = 1;
  25.         }
  26.     }
  27.     for (int i = 0; i < nr; i++) {
  28.         if (rr[i]) {
  29.             //printf("need fix -- %d\n", i);
  30.             bool flag = false;
  31.             for (int j = 0; j < nc; j++) {
  32.                 if (cc[j]) {
  33.                     rr[i] = false;
  34.                     cc[j] = false;
  35.                     a[i][j] ^= 1;
  36.                     flag = true;
  37.                     break;
  38.                 }
  39.             }
  40.             if (!flag) {
  41.                 //puts("oops");
  42.                 rr[i] = false;
  43.                 cc[0] = true;
  44.                 a[i][0] ^= 1;
  45.             }
  46.         }
  47.     }
  48.     /*
  49.     puts("---");
  50.     for (int i = 0; i < nr; i++) {
  51.         for (int j = 0; j < nc; j++) {
  52.             printf("%d", a[i][j]);
  53.         }
  54.         puts("");
  55.     }
  56.     puts("---");
  57.     */
  58.     for (int i = 0; i < nc; i++) {
  59.         if (cc[i]) {
  60.             bool flag = false;
  61.             for (int j = 0; j < nr; j++) {
  62.                 if (rr[j]) {
  63.                     cc[i] = false;
  64.                     rr[j] = false;
  65.                     a[j][i] ^= 1;
  66.                     flag = true;
  67.                     break;
  68.                 }
  69.             }
  70.             if (!flag) {
  71.                 cc[i] = false;
  72.                 rr[0] = true;
  73.                 a[0][i] ^= 1;
  74.             }
  75.         }
  76.     }
  77.     for (int i = 0; i < nr; i++) {
  78.         if (rr[i]) {
  79.             puts("-1");
  80.             return 0;
  81.         }
  82.     }
  83.     for (int i = 0; i < nc; i++) {
  84.         if (cc[i]) {
  85.             puts("-1");
  86.             return 0;
  87.         }
  88.     }
  89.     for (int i = 0; i < nr; i++) {
  90.         int cnt = 0;
  91.         for (int j = 0; j < nc; j++) {
  92.             cnt += a[i][j];
  93.         }
  94.     }
  95.     for (int i = 0; i < nr; i++) {
  96.         for (int j = 0; j < nc; j++) {
  97.             printf("%d", a[i][j]);
  98.         }
  99.         puts("");
  100.     }
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement