-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1080.cpp
49 lines (39 loc) · 1.01 KB
/
1080.cpp
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
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
using namespace std;
char arr1[50][50];
char arr2[50][50];
int cnt;
void reverse(int row, int col){
for(int i = row; i < row+3; i++){
for(int j = col; j < col+3; j++){
arr1[i][j] = (arr1[i][j] == '1' ? '0' : '1');
}
}
}
int main(void) {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int N, M;
cin >> N >> M;
for(int i = 0; i < N; i++)
for(int j = 0; j < M; j++)
cin >> arr1[i][j];
for(int i = 0; i < N; i++)
for(int j = 0; j < M; j++)
cin >> arr2[i][j];
for(int i = 0; i < N-2; i++){
for(int j = 0; j < M-2; j++){
if(arr1[i][j] != arr2[i][j]){
reverse(i, j);
cnt++;
}
}
}
bool flag = false;
for(int i = 0; i < N; i++)
for(int j = 0; j < M; j++)
if(arr1[i][j] != arr2[i][j])
flag = true;
if(flag) cout << -1 << '\n';
else cout << cnt << '\n';
return 0;
}