-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolored_paper.cpp
64 lines (55 loc) · 1.05 KB
/
colored_paper.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
// https://www.acmicpc.net/problem/2630
#include <bits/stdc++.h>
using namespace std;
void rec(int, int, int);
int arr[128+1][128+1]; // 1-based
int n_white;
int n_blue;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
for (int i = 1; i<=n; ++i) {
for (int j = 1; j<=n; ++j) {
cin>>arr[i][j];
}
}
rec(n,1,1);
cout << n_white << '\n' << n_blue;
return 0;
}
void rec(int n, int x, int y)
{
if (n==1) {
(arr[x][y]) ? ++n_blue : ++n_white;
return;
}
bool is_white = true;
bool is_blue = true;
for (int i = x; i<x+n; ++i) {
for (int j = y; j<y+n; ++j) {
if (arr[i][j]) {
is_white=false;
}
else {
is_blue=false;
}
}
}
if (is_white) {
++n_white;
}
else if (is_blue) {
++n_blue;
}
else {
n/=2;
rec(n,x,y);
rec(n,x,y+n);
rec(n,x+n,y);
rec(n,x+n,y+n);
}
return;
}