[백준] 1780 종이의 개수 (c++)

2022. 7. 7. 23:12알고리즘/백준

728x90

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int n;
long long int arr[3001][3001];
int count_number[3];
string str, tmp;
void bh(int x, int y, int n) {
	int first = arr[x][y];
	bool flag = true;
	
	for (int i = x; i < x + n; i++) {
		for (int j = y; j < y + n; j++) {
			if (arr[i][j] != first) {
				flag = false;
				break;
			}
		}
	}

	if (flag) {
		count_number[first + 1]++;

	}

	else {
		for (int a = x; a < x + n; a += n / 3) {
			for (int b = y; b < y + n; b += n / 3) {
				bh(a, b, n / 3);
			}
		}
	}
}
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int y = 0; y < n; y++) {
		for (int x = 0; x < n; x++) {
			cin >> arr[y][x];
		}
	}

	bh(0, 0, n);

	for (int i = 0; i < 3; i++) {
		cout << count_number[i] << '\n';
	}
	return 0;
}
728x90

'알고리즘 > 백준' 카테고리의 다른 글

[백준] 연결 요소의 개수 c++  (0) 2022.07.09
[백준] 1927 최소 힙 c++  (0) 2022.07.08
[백준] 잃어버린 괄호 1541 c++  (0) 2022.07.06
[백준] 11444 피보나치 수 6  (0) 2022.07.05
[백준] 11727 2×n 타일링 2 c++  (0) 2022.07.04