-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1080.cpp
More file actions
41 lines (37 loc) · 920 Bytes
/
1080.cpp
File metadata and controls
41 lines (37 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <cstdio>
#include <iostream>
using namespace std;
int n, m;
int a[51][51];
int b[51][51];
bool check_ans() {
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (a[i][j] != b[i][j]) return false;
return true;
}
void modify(int x, int y) {
for (int i = x; i < x + 3; i++)
for (int j = y; j < y + 3; j++) a[i][j] = !a[i][j];
}
int main() {
int ans = 0;
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) scanf("%1d", &a[i][j]);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) scanf("%1d", &b[i][j]);
for (int i = 0; i <= n - 3; i++) {
for (int j = 0; j <= m - 3; j++) {
if (a[i][j] ^ b[i][j]) {
modify(i, j);
ans++;
}
}
}
if (check_ans()) {
cout << ans << "\n";
} else {
cout << -1 << "\n";
}
}