-
Notifications
You must be signed in to change notification settings - Fork 0
/
1080.cpp
83 lines (71 loc) · 1.42 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
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
using namespace std;
#define MAX 50
char arry1[MAX][MAX];
char arry2[MAX][MAX];
void Insert(int N, int M) // 배열 넣는 함수
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
char num;
cin >> num;
arry1[i][j] = num;
}
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
char num;
cin >> num;
arry2[i][j] = num;
}
}
}
void change(char arry1[][MAX], int y, int x) // 1->0, 0->1
{
for (int i = y; i < y + 3; i++)
{
for (int j = x; j < x + 3; j++)
{
if (arry1[i][j] == '1')
arry1[i][j] = '0';
else if (arry1[i][j] == '0')
arry1[i][j] = '1';
}
}
}
int Solution(int N, int M) // 변환
{
int answer = 0;
for (int i = 0; i < N - 2; i++)
{
for (int j = 0; j < M - 2; j++)
{
if (arry1[i][j] != arry2[i][j])
{
change(arry1, i, j);
answer++;
}
}
}
for(int i=0; i<N; i++)
{
for(int j=0; j<M; j++)
{
if(arry1[i][j] != arry2[i][j])// 조건
return -1;
}
}
return answer;
}
int main()
{
int N, M;
cin >> N >> M;
Insert(N, M);
cout << Solution(N, M) << '\n';
return 0;
}