-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ1080.java
More file actions
61 lines (53 loc) · 1.33 KB
/
BOJ1080.java
File metadata and controls
61 lines (53 loc) · 1.33 KB
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ1080 {
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
st=new StringTokenizer(br.readLine()," ");
int cnt=0;
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[][] A=new int[N][M];
int[][] B=new int[N][M];
for(int i = 0; i < N; i++) {
String input = br.readLine();
for(int j = 0; j < M; j++) {
A[i][j]=input.charAt(j)-'0';
}
}
for(int i = 0; i < N; i++) {
String input = br.readLine();
for(int j = 0; j < M; j++) {
B[i][j]=input.charAt(j)-'0';
}
}
if(N >= 3 && M >= 3) {
for(int i = 0; i < N-2; i++) {
for(int j = 0; j < M-2; j++) {
if(A[i][j]!=B[i][j]) {
for(int x = i; x < i+3; x++) {
for(int y = j; y < j+3; y++) {
if(A[x][y]==0) A[x][y]=1;
else A[x][y]=0;
}
}
cnt++;
}
}
}
}
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
if(A[i][j]!=B[i][j]) {
System.out.println(-1);
return;
}
}
}
System.out.println(cnt);
}
}