Dolphins의 HelloWorld

[백준]Baekjoon1080(Greedy Algorithm) 본문

Algorithm/baekjoon문제풀이

[백준]Baekjoon1080(Greedy Algorithm)

돌핀's 2018. 8. 30. 18:43


문제 링크 : https://www.acmicpc.net/problem/1080


#include <iostream>
#include <vector>

using namespace std;

int A[50][50];
int B[50][50];

int main()
{
	int N, M;
	scanf("%d %d", &N, &M);

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			scanf("%1d", &A[i][j]);
		}
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			scanf("%1d", &B[i][j]);
		}
	}
	int count = 0;

	for (int i = 0; i < N-2; i++) {
		for (int j = 0; j < M-2; j++) {
			if (A[i][j] != B[i][j]) {
				count++;
				for (int x = i; x <= i + 2; x++) {
					for (int y = j; y <= j + 2; y++) {
						A[x][y] = 1 - A[x][y];
					}
				}
			}
		}
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (A[i][j] != B[i][j]) count = -1;
		}
	}

	printf("%d\n", count);
}


Comments