[BOJ] 2630 색종이 만들기

Time Lapse :NONE

2630.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int arr[128][128];
int N;
int white = 0, blue = 0;

void find(int length, int x, int y)
{
bool same = true;

if (length == 1)
{
if (arr[x][y] == 0)
white++;
else
blue++;

return;
}

for (int i = x; i < x + length; i++)
{
if (!same)
break;

for (int j = y; j < y + length; j++)
{
if (arr[x][y] != arr[i][j])
{
same = false;
find(length / 2, x, y);
find(length / 2, x+(length/2), y);
find(length / 2, x, y + (length / 2));
find(length / 2, x + (length / 2), y + (length / 2));
break;
}
}
}

if (same)
{
if (arr[x][y] == 0)
white++;
else
blue++;

return;
}
}

int main(void)
{
cin >> N;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
cin >> arr[i][j];
}
}

find(N,0,0);
cout << white << endl << blue << endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/2630/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.