[BOJ] 1780 종이의 개수

Time Lapse :NONE

1780.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <math.h>
#include <algorithm>
#include <cstring>

using namespace std;

#define MAXSIZE 4000

int arr[MAXSIZE][MAXSIZE];

int MINUS = 0;
int ZERO = 0;
int PLUS = 0;

void add(int x, int y)
{
if (arr[x][y] == -1)
MINUS++;
if (arr[x][y] == 0)
ZERO++;
if (arr[x][y] == 1)
PLUS++;

return;
}

void answer_func(int lenth,int x, int y)
{
bool tf = true;

if (lenth == 1)
{
add(x, y);
return;
}

for (int i = x; i < x + lenth; i++)
{
if (!tf)
break;

for (int j = y; j < y + lenth; j++)
{
if (arr[x][y] != arr[i][j])
{
tf = false;
break;
}
}
}

if (tf)
{
add(x, y);
return;
}
else
{
answer_func(lenth / 3, x, y);
answer_func(lenth / 3, x + lenth / 3, y);
answer_func(lenth / 3, x + 2 *lenth / 3, y);

answer_func(lenth / 3, x, y + lenth / 3);
answer_func(lenth / 3, x + lenth / 3, y + lenth / 3);
answer_func(lenth / 3, x + 2 * lenth / 3, y + lenth / 3);

answer_func(lenth / 3, x, y + 2 * lenth / 3);
answer_func(lenth / 3, x + lenth / 3, y + 2 * lenth / 3);
answer_func(lenth / 3, x + 2 * lenth / 3, y + 2 * lenth / 3);
}
}

int main(void)
{
int n, k;

cin >> n;

for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cin >> arr[i][j];
}
}
answer_func(n,0,0);

cout << MINUS << endl << ZERO << endl << PLUS << endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/1780/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.