Skip to content

Commit 899f2c2

Browse files
committed
[Gold III] Title: 색종이 - 3, Time: 1152 ms, Memory: 17668 KB -BaekjoonHub
1 parent ff98d3a commit 899f2c2

2 files changed

Lines changed: 123 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# [Gold III] 색종이 - 3 - 2571
2+
3+
[문제 링크](https://www.acmicpc.net/problem/2571)
4+
5+
### 성능 요약
6+
7+
메모리: 17668 KB, 시간: 1152 ms
8+
9+
### 분류
10+
11+
구현, 누적 합
12+
13+
### 제출 일자
14+
15+
2025년 7월 31일 00:11:06
16+
17+
### 문제 설명
18+
19+
<p>가로, 세로의 크기가 각각 100인 정사각형 모양의 흰색 도화지가 있다. 이 도화지 위에 가로, 세로의 크기가 각각 10인 정사각형 모양의 검은색 색종이를 색종이의 변과 도화지의 변이 평행하도록 붙인다. 이러한 방식으로 색종이를 한 장 또는 여러 장 붙인 후 도화지에서 검은색 직사각형을 잘라내려고 한다. 직사각형 또한 그 변이 도화지의 변과 평행하도록 잘라내어야 한다.</p>
20+
21+
<p>예를 들어 흰색 도화지 위에 세 장의 검은색 색종이를 <그림 1>과 같은 모양으로 붙였다. <그림 1>에 표시된 대로 검은색 직사각형을 잘라내면 그 넓이는 22×5=110이 된다.</p>
22+
23+
<p style="text-align: center;"><img alt="" src="https://upload.acmicpc.net/dd83053d-3e5d-4233-a5e9-467be7ea8556/-/preview/" style="width: 324px; height: 257px;"></p>
24+
25+
<p style="text-align: center;"><그림 1></p>
26+
27+
<p style="text-align: center;"><img alt="" src="https://upload.acmicpc.net/7a7ebae5-6db9-4662-8a1e-03c2a884f771/-/preview/" style="width: 324px; height: 256px;"></p>
28+
29+
<p style="text-align: center;"><그림 2></p>
30+
31+
<p>반면 <그림 2>에 표시된 대로 검은색 직사각형을 잘라내면 그 넓이는 8×15=120이 된다.</p>
32+
33+
<p>검은색 색종이의 수와 각 색종이를 붙인 위치가 주어질 때 잘라낼 수 있는 검은색 직사각형의 최대 넓이를 구하는 프로그램을 작성하시오.</p>
34+
35+
### 입력
36+
37+
<p>첫째 줄에 색종이의 수가 주어진다. 이어 둘째 줄부터 한 줄에 하나씩 색종이를 붙인 위치가 주어진다. 색종이를 붙인 위치는 두 개의 자연수로 주어지는데 첫 번째 자연수는 색종이의 왼쪽 변과 도화지의 왼쪽 변 사이의 거리이고, 두 번째 자연수는 색종이의 아래쪽 변과 도화지의 아래쪽 변 사이의 거리이다. 색종이의 수는 100이하이며, 색종이가 도화지 밖으로 나가는 경우는 없다.</p>
38+
39+
### 출력
40+
41+
<p>첫째 줄에 잘라낼 수 있는 검은색 직사각형의 최대 넓이를 출력한다.</p>
42+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
static int[] selected;
6+
static boolean[][] map;
7+
static List<p> rectangle;
8+
static int n, ans;
9+
static StringTokenizer st;
10+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
public static void main(String[] args) throws Exception{
12+
inputSetting();
13+
combi(0, 0);
14+
System.out.println(ans);
15+
}
16+
17+
static void combi(int cnt, int start){
18+
if(cnt == 2){
19+
ans = Math.max(ans, rectangleSize(rectangle.get(selected[0]), rectangle.get(selected[1])));
20+
return;
21+
}
22+
23+
for(int i = start; i < rectangle.size(); i++){
24+
selected[cnt] = i;
25+
combi(cnt + 1, i + 1);
26+
}
27+
}
28+
29+
static int rectangleSize(p one, p two){
30+
int minX, minY, maxX, maxY, result;
31+
32+
minX = Math.min(one.x, two.x);
33+
maxX = Math.max(one.x, two.x);
34+
minY = Math.min(one.y, two.y);
35+
maxY = Math.max(one.y, two.y);
36+
if((maxX - minX) * (maxY - minY) <= ans) return 0;
37+
38+
for(int i = minX; i < maxX; i++){
39+
for(int j = minY; j < maxY; j++){
40+
if(map[i][j]) return 0;
41+
}
42+
}
43+
return (maxX - minX) * (maxY - minY);
44+
}
45+
46+
static void inputSetting() throws Exception{
47+
map = new boolean[101][101];
48+
selected = new int[2];
49+
50+
n = Integer.parseInt(br.readLine());
51+
for (int i = 0; i < 101; i++) Arrays.fill(map[i], true);
52+
53+
rectangle = new ArrayList<>();
54+
55+
int x, y, nx, ny;
56+
for(int i = 0; i < n; i++){
57+
st = new StringTokenizer(br.readLine());
58+
59+
x = Integer.parseInt(st.nextToken());
60+
y = Integer.parseInt(st.nextToken());
61+
nx = x + 10;
62+
ny = y + 10;
63+
64+
for(int dx = x; dx <= nx; dx++){
65+
for(int dy = y; dy <= ny; dy++){
66+
rectangle.add(new p(dx, dy));
67+
if(dx != nx && dy != ny) map[dx][dy] = false;
68+
}
69+
}
70+
}
71+
}
72+
73+
static class p{
74+
int x, y;
75+
76+
p(int x, int y){
77+
this.x = x;
78+
this.y = y;
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)