-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1080.java
More file actions
58 lines (48 loc) · 965 Bytes
/
P1080.java
File metadata and controls
58 lines (48 loc) · 965 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package BOJ;
import java.util.*;
public class P1080 {
static int[][] a = new int[50][50];
static int[][] b = new int[50][50];
public static void toggle(int x, int y){
for(int i = x-1; i<=x+1;i++){
for(int j = y-1;j<=y+1;j++){
a[i][j] = 1-a[i][j];
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
sc.nextLine();
for(int i=0;i<n;i++){
String line = sc.nextLine();
for(int j=0;j<m;j++){
a[i][j] = line.charAt(j)-'0';
}
}
for(int i=0;i<n;i++){
String line = sc.nextLine();
for(int j=0;j<m;j++){
b[i][j] = line.charAt(j)-'0';
}
}
int ans = 0;
for(int i=0;i<n-2;i++){
for(int j=0;j<m-2;j++){
if(a[i][j]!=b[i][j]){
ans+=1;
toggle(i+1,j+1);
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(a[i][j]!=b[i][j]){
ans=-1;
}
}
}
System.out.println(ans);
}
}