We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2723e4d commit 074eda7Copy full SHA for 074eda7
minjeong/Divide&Conquer/2024-07-30-[백준]-#2630-색종이만들기.py
@@ -0,0 +1,32 @@
1
+import sys
2
+input = sys.stdin.readline
3
+
4
+def find_number_of_paper(x_start, y_start, n):
5
+ global white_cnt, blue_cnt
6
+ check_sum = 0 # 색종이가 만들어지는지 여부를 확인하기 위한 변수
7
+ for i in range(x_start, x_start + n):
8
+ for j in range(y_start, y_start + n):
9
+ check_sum += colored_paper[i][j]
10
+ if check_sum == 0: # 하얀 색종이라면
11
+ white_cnt += 1
12
+ elif check_sum == n * n: # 파란 색종이라면
13
+ blue_cnt += 1
14
+ else: # 해당 사항 없으면 다시 분할
15
+ find_number_of_paper(x_start, y_start, n // 2)
16
+ find_number_of_paper(x_start + n // 2, y_start, n // 2)
17
+ find_number_of_paper(x_start, y_start + n // 2, n // 2)
18
+ find_number_of_paper(x_start + n // 2, y_start + n // 2, n // 2)
19
20
+n = int(input()) # 한 변의 길이
21
+colored_paper = [] # 정사각형칸의 색
22
+for _ in range(n):
23
+ li = list(map(int, input().split()))
24
+ colored_paper.append(li)
25
26
+white_cnt = 0 # 햐얀색 색종이의 개수
27
+blue_cnt = 0 # 파란색 색종이의 개수
28
29
+find_number_of_paper(0, 0, n)
30
31
+print(white_cnt)
32
+print(blue_cnt)
0 commit comments