Skip to content

Commit 249605f

Browse files
committed
[Silver II] Title: 종이의 개수, Time: 1160 ms, Memory: 321820 KB -BaekjoonHub
1 parent 4242eed commit 249605f

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# [Silver II] 종이의 개수 - 1780
2+
3+
[문제 링크](https://www.acmicpc.net/problem/1780)
4+
5+
### 성능 요약
6+
7+
메모리: 321820 KB, 시간: 1160 ms
8+
9+
### 분류
10+
11+
분할 정복, 재귀
12+
13+
### 제출 일자
14+
15+
2025년 8월 4일 23:16:38
16+
17+
### 문제 설명
18+
19+
<p>N×N크기의 행렬로 표현되는 종이가 있다. 종이의 각 칸에는 -1, 0, 1 중 하나가 저장되어 있다. 우리는 이 행렬을 다음과 같은 규칙에 따라 적절한 크기로 자르려고 한다.</p>
20+
21+
<ol>
22+
<li>만약 종이가 모두 같은 수로 되어 있다면 이 종이를 그대로 사용한다.</li>
23+
<li>(1)이 아닌 경우에는 종이를 같은 크기의 종이 9개로 자르고, 각각의 잘린 종이에 대해서 (1)의 과정을 반복한다.</li>
24+
</ol>
25+
26+
<p>이와 같이 종이를 잘랐을 때, -1로만 채워진 종이의 개수, 0으로만 채워진 종이의 개수, 1로만 채워진 종이의 개수를 구해내는 프로그램을 작성하시오.</p>
27+
28+
### 입력
29+
30+
<p>첫째 줄에 N(1 ≤ N ≤ 3<sup>7</sup>, N은 3<sup>k</sup> 꼴)이 주어진다. 다음 N개의 줄에는 N개의 정수로 행렬이 주어진다.</p>
31+
32+
### 출력
33+
34+
<p>첫째 줄에 -1로만 채워진 종이의 개수를, 둘째 줄에 0으로만 채워진 종이의 개수를, 셋째 줄에 1로만 채워진 종이의 개수를 출력한다.</p>
35+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
static int[][] map;
6+
static int[] count = new int[3];
7+
8+
public static void main(String[] args) throws Exception {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
int n = Integer.parseInt(br.readLine());
11+
map = new int[n][n];
12+
for (int i = 0; i < n; i++) {
13+
int[] inputArr = Arrays.stream(br.readLine().split(" "))
14+
.mapToInt(Integer::parseInt)
15+
.toArray();
16+
System.arraycopy(inputArr, 0, map[i], 0, n);
17+
}
18+
solve(0, 0, n);
19+
System.out.println(count[0]);
20+
System.out.println(count[1]);
21+
System.out.println(count[2]);
22+
}
23+
24+
static void solve(int x, int y, int size) {
25+
int v = map[x][y];
26+
for (int i = x; i < x + size; i++) {
27+
for (int j = y; j < y + size; j++) {
28+
if (map[i][j] != v) {
29+
int newSize = size / 3;
30+
for (int dx = 0; dx < 3; dx++) {
31+
for (int dy = 0; dy < 3; dy++) {
32+
solve(x + dx * newSize, y + dy * newSize, newSize);
33+
}
34+
}
35+
return;
36+
}
37+
}
38+
}
39+
count[v + 1]++;
40+
}
41+
}

0 commit comments

Comments
 (0)