문제출처 : https://www.acmicpc.net/problem/1080
푸는건 쉬운편이였다.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int N = 0, M = 0, matrix[2][50][50], cnt = 0;
cin >> N >> M;
for (int k = 0; k < 2; k++)
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
scanf("%1d", &matrix[k][i][j]);
for(int i=0;i<=N-3;i++)
for(int j=0;j<=M-3;j++)
if (matrix[0][i][j] != matrix[1][i][j])
{
cnt++;
for (int a = 0; a < 3; a++)
for(int b = 0; b < 3; b++)
{
if (matrix[0][i + a][j + b] == 1)
matrix[0][i + a][j + b] = 0;
else
matrix[0][i + a][j + b] = 1;
}
}
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
if (matrix[0][i][j] != matrix[1][i][j])
cnt = -1;
cout << cnt;
return 0;
}