-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Silver II] Title: 종이의 개수, Time: 2092 ms, Memory: 69428 KB -BaekjoonHub
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# [Silver II] 종이의 개수 - 1780 | ||
|
||
[문제 링크](https://www.acmicpc.net/problem/1780) | ||
|
||
### 성능 요약 | ||
|
||
메모리: 69428 KB, 시간: 2092 ms | ||
|
||
### 분류 | ||
|
||
분할 정복, 재귀 | ||
|
||
### 제출 일자 | ||
|
||
2024년 8월 30일 12:52:02 | ||
|
||
### 문제 설명 | ||
|
||
<p>N×N크기의 행렬로 표현되는 종이가 있다. 종이의 각 칸에는 -1, 0, 1 중 하나가 저장되어 있다. 우리는 이 행렬을 다음과 같은 규칙에 따라 적절한 크기로 자르려고 한다.</p> | ||
|
||
<ol> | ||
<li>만약 종이가 모두 같은 수로 되어 있다면 이 종이를 그대로 사용한다.</li> | ||
<li>(1)이 아닌 경우에는 종이를 같은 크기의 종이 9개로 자르고, 각각의 잘린 종이에 대해서 (1)의 과정을 반복한다.</li> | ||
</ol> | ||
|
||
<p>이와 같이 종이를 잘랐을 때, -1로만 채워진 종이의 개수, 0으로만 채워진 종이의 개수, 1로만 채워진 종이의 개수를 구해내는 프로그램을 작성하시오.</p> | ||
|
||
### 입력 | ||
|
||
<p>첫째 줄에 N(1 ≤ N ≤ 3<sup>7</sup>, N은 3<sup>k</sup> 꼴)이 주어진다. 다음 N개의 줄에는 N개의 정수로 행렬이 주어진다.</p> | ||
|
||
### 출력 | ||
|
||
<p>첫째 줄에 -1로만 채워진 종이의 개수를, 둘째 줄에 0으로만 채워진 종이의 개수를, 셋째 줄에 1로만 채워진 종이의 개수를 출력한다.</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
|
||
N = int(input()) | ||
arr = [list(map(int, input().split())) for _ in range(N)] | ||
cnts = {-1 : 0, 0 : 0, 1 : 0} | ||
|
||
def partial(sr, sc, n): | ||
num = arr[sr][sc] | ||
if n == 1: | ||
cnts[num] += 1 | ||
return | ||
|
||
flag = True | ||
for i in range(sr, sr+n): | ||
for j in range(sc, sc+n): | ||
if arr[i][j] != num: | ||
flag = False | ||
new_n = n//3 | ||
partial(sr,sc,new_n) | ||
partial(sr,sc+new_n,new_n) | ||
partial(sr,sc+new_n*2,new_n) | ||
partial(sr+new_n,sc,new_n) | ||
partial(sr+new_n,sc+new_n,new_n) | ||
partial(sr+new_n,sc+new_n*2,new_n) | ||
partial(sr+new_n*2,sc,new_n) | ||
partial(sr+new_n*2,sc+new_n,new_n) | ||
partial(sr+new_n*2,sc+new_n*2,new_n) | ||
break | ||
if not flag : break | ||
|
||
if flag: | ||
cnts[num] += 1 | ||
|
||
partial(0,0,N) | ||
|
||
for num, cnt in cnts.items(): | ||
print(cnt) |