-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2630.py
More file actions
72 lines (59 loc) · 1.72 KB
/
2630.py
File metadata and controls
72 lines (59 loc) · 1.72 KB
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
# author madaniel47
n = int(input())
arr = []
for i in range(n):
row = list(map(int, input().split()))
arr.append(row)
numOfZeroPapers = 0
numOfOnePapers = 0
def dividePaper(r, c, length):
global numOfZeroPapers, numOfOnePapers
# 길이가 1칸이면 색깔 return
if length == 2:
result = arr[r][c] + arr[r+1][c] + arr[r][c+1] + arr[r+1][c+1]
if result == 4:
return 1
elif result == 0:
return 0
else:
numOfOnePapers += result
numOfZeroPapers += (4-result)
return -1
# 길이가 1칸이 아닌 경우
# 4칸 쪼개서 recursive
leftTop = dividePaper(r, c, int(length / 2))
leftBot = dividePaper(r + int(length / 2), c, int(length / 2))
rightTop = dividePaper(r, c + int(length / 2), int(length / 2))
rightBot = dividePaper(r + int(length / 2), c + int(length / 2), int(length / 2))
if (leftTop == leftBot) and (leftBot == rightTop) and (rightTop == rightBot):
return leftTop
else:
if leftTop == 1:
numOfOnePapers += 1
elif leftTop == 0:
numOfZeroPapers += 1
if rightTop == 1:
numOfOnePapers += 1
elif rightTop == 0:
numOfZeroPapers += 1
if leftBot == 1:
numOfOnePapers += 1
elif leftBot == 0:
numOfZeroPapers += 1
if rightBot == 1:
numOfOnePapers += 1
elif rightBot == 0:
numOfZeroPapers += 1
return -1
# dividePaper func 실행
master = dividePaper(0, 0, n)
if master == -1:
print(numOfZeroPapers)
print(numOfOnePapers)
else:
if master == 0:
print(1)
print(0)
else:
print(0)
print(1)