-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1080.cpp
72 lines (62 loc) · 1.48 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// Created by LG on 2021-10-05.
//
#include <iostream>
#include <vector>
using namespace std;
int n, m;
bool compare(vector<vector<bool>> m1, vector<vector<bool>> m2){
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(m1[i][j] != m2[i][j])
return false;
}
}
return true;
}
int find(vector<vector<bool>> &m1, vector<vector<bool>> m2){
int cnt = 0;
for(int i=0; i<n-2; i++){
for(int j=0; j<m-2; j++){
if(m1[i][j] != m2[i][j]) {
for(int k=0; k<3; k++) {
for(int p=0; p<3; p++)
m1[i+k][j+p] = !m1[i+k][j+p];
}
cnt++;
if(compare(m1, m2))
return cnt;
}
}
}
return -1;
}
int main(){
cin >> n >> m;
vector<vector<bool>> m1(n, vector<bool>(m, 0));
vector<vector<bool>> m2(n, vector<bool>(m, 0));
for(int i=0; i<n; i++){
string s;
cin >> s;
for(int j=0; j<m; j++){
int t = s[j] - '0';
m1[i][j] = t;
}
}
for(int i=0; i<n; i++){
string s;
cin >> s;
for(int j=0; j<m; j++){
int t = s[j] - '0';
m2[i][j] = t;
}
}
if(compare(m1, m2))
cout << 0;
else{
if(n<3 || m<3)
cout << -1;
else
cout << find(m1, m2);
}
}