-
Notifications
You must be signed in to change notification settings - Fork 1
/
쿼드압축후개수세기_mj.cs
51 lines (47 loc) · 1.06 KB
/
쿼드압축후개수세기_mj.cs
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
using System;
using System.Linq;
public class Solution
{
int[,] temp;
int[] answer = new int[] { 0, 0 };
public int[] solution(int[,] arr)
{
temp = arr;
int len = arr.GetLength(0);
DFS(0, 0, len);
return answer;
}
public void DFS(int x, int y, int len)
{
bool check_zero = true;
bool check_one = true;
for (int i = x; i < x + len; i++)
{
for (int j = y; j < y + len; j++)
{
if (temp[i, j] == 0)
{
check_one = false;
}
if (temp[i, j] == 1)
{
check_zero = false;
}
}
}
if (check_zero)
{
answer[0]++;
return;
}
if (check_one)
{
answer[1]++;
return;
}
DFS(x, y, len / 2);
DFS(x, y + len / 2, len / 2);
DFS(x + len / 2, y, len / 2);
DFS(x + len / 2, y + len / 2, len / 2);
}
}