[BOJ] 1780번 : 종이의 개수

2024. 8. 15. 22:52Algorithm

1. problem :

https://www.acmicpc.net/problem/1780

 

2. solution 1 :

#include <bits/stdc++.h>
using namespace std;
int paper[2188][2188];

int cnt[3]; // -1,0,1을 담는 배열; 

bool check(int x, int y, int n) {
	for (int i = x; i < x + n; i++) {
		for (int j = y; j < y + n; j++) {
			if (paper[x][y] != paper[i][j]) {
				return false;
			}
		}
	}
	return true;
}

void solve(int x, int y, int z) {
	if (check(x, y, z)) {
		cnt[paper[x][y] + 1] += 1;
		return;
	}
	int n = z / 3;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			solve(x + n * i, y + n * j, n);
		}
	}
}


int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int N;
	cin >> N;
	for (int i = 0; i < N;i++) {
		for (int j = 0; j < N; j++) {
			cin >> paper[i][j];
		}
	}
	solve(0, 0, N);
	for (int i = 0; i < 3; i++) cout << cnt[i] << '\n';
}

<source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x0B/solutions/1780.cpp >

 

basic-algo-lecture/0x0B/solutions/1780.cpp at master · encrypted-def/basic-algo-lecture

바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.

github.com