[백준] 2630 색종이 만들기

0

백준

목록 보기
205/271
post-thumbnail
post-custom-banner

[백준] 2630 색종이 만들기

#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

int n;
vector<vector<int>> board;

int white = 0;
int blue = 0;

void solution(int startR, int startC, int size) {
	int color = board[startR][startC];

	//색종이 모두 같은 색으로 칠해져있는지 확인
	bool sameColor = true;
	for (int r = startR; r < startR + size; ++r) {
		for (int c = startC; c < startC + size; ++c) {
			if (board[r][c] != color) {
				sameColor = false;
				break;
			}
		}
		if (!sameColor) break;
	}

	if (sameColor) {
		if (color == 0) white++;
		else blue++;
		return;
	}

	//색종이 4등분
	int halfSize = size / 2;
	solution(startR, startC, halfSize);
	solution(startR, startC + halfSize, halfSize);
	solution(startR + halfSize, startC, halfSize);
	solution(startR + halfSize, startC + halfSize, halfSize);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	cin >> n;
	for (int i = 0; i < n; ++i) {
		vector<int> row;
		for (int j = 0; j < n; ++j) {
			int input;
			cin >> input;
			row.push_back(input);
		}
		board.push_back(row);
	}

	solution(0, 0, n);

	cout << white << "\n" << blue;

	return 0;
}
profile
Be able to be vulnerable, in search of truth
post-custom-banner

0개의 댓글