-
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 V] Title: 종이자르기, Time: 36 ms, Memory: 31252 KB -BaekjoonHub
- Loading branch information
1 parent
c3498bc
commit 086e663
Showing
2 changed files
with
81 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,40 @@ | ||
# [Silver V] 종이자르기 - 2628 | ||
|
||
[문제 링크](https://www.acmicpc.net/problem/2628) | ||
|
||
### 성능 요약 | ||
|
||
메모리: 31252 KB, 시간: 36 ms | ||
|
||
### 분류 | ||
|
||
구현, 정렬 | ||
|
||
### 제출 일자 | ||
|
||
2024년 8월 9일 13:14:20 | ||
|
||
### 문제 설명 | ||
|
||
<p>아래 <그림 1>과 같이 직사각형 모양의 종이가 있다. 이 종이는 가로방향과 세로 방향으로 1㎝마다 점선이 그어져 있다. 가로 점선은 위에서 아래로 1번부터 차례로 번호가 붙어 있고, 세로 점선은 왼쪽에서 오른쪽으로 번호가 붙어 있다.</p> | ||
|
||
<p style="text-align: center;"><img alt="" src="https://upload.acmicpc.net/1e689dae-2d24-463b-8725-fb58ae8cd2ba/-/preview/" style="width: 218px; height: 181px;"></p> | ||
|
||
<p style="text-align: center;"><그림 1></p> | ||
|
||
<p>점선을 따라 이 종이를 칼로 자르려고 한다. 가로 점선을 따라 자르는 경우는 종이의 왼쪽 끝에서 오른쪽 끝까지, 세로 점선인 경우는 위쪽 끝에서 아래쪽 끝까지 한 번에 자른다. 예를 들어, <그림 1>의 가로 길이 10㎝이고 세로 길이 8㎝인 종이를 3번 가로 점선, 4번 세로 점선, 그리고 2번 가로 점선을 따라 자르면 <그림 2>와 같이 여러 개의 종이 조각으로 나뉘게 된다. 이때 가장 큰 종이 조각의 넓이는 30㎠이다.</p> | ||
|
||
<p style="text-align: center;"><img alt="" src="https://upload.acmicpc.net/cf033b95-91ef-4e71-8f2c-49c653e27622/-/preview/" style="width: 230px; height: 207px;"></p> | ||
|
||
<p style="text-align: center;"><그림 2></p> | ||
|
||
<p>입력으로 종이의 가로 세로 길이, 그리고 잘라야할 점선들이 주어질 때, 가장 큰 종이 조각의 넓이가 몇 ㎠인지를 구하는 프로그램을 작성하시오.</p> | ||
|
||
### 입력 | ||
|
||
<p>첫줄에는 종이의 가로와 세로의 길이가 차례로 자연수로 주어진다. 가로와 세로의 길이는 최대 100㎝이다. 둘째 줄에는 칼로 잘라야하는 점선의 개수가 주어진다. 셋째 줄부터 마지막 줄까지 한 줄에 점선이 하나씩 아래와 같은 방법으로 입력된다. 가로로 자르는 점선은 0과 점선 번호가 차례로 주어지고, 세로로 자르는 점선은 1과 점선 번호가 주어진다. 입력되는 두 숫자 사이에는 빈 칸이 하나씩 있다.</p> | ||
|
||
### 출력 | ||
|
||
<p>첫째 줄에 가장 큰 종이 조각의 넓이를 출력한다. 단, 넓이의 단위는 출력하지 않는다.</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,41 @@ | ||
|
||
N, M = map(int, input().split()) | ||
T = int(input()) | ||
|
||
|
||
# cut_point 만들기 | ||
# tip: (0,0), (M,N) 사전에 넣어주기 | ||
x_cut_points = [0, M] | ||
y_cut_points = [0, N] | ||
|
||
for i in range(T): | ||
is_y_cut_point, cut_point = map(int, input().split()) | ||
|
||
if(is_y_cut_point): | ||
y_cut_points.append(cut_point) | ||
else: | ||
x_cut_points.append(cut_point) | ||
|
||
# 정렬 후 자르기 | ||
x_cut_points.sort() | ||
y_cut_points.sort() | ||
|
||
# print(x_cut_points) | ||
# print(y_cut_points) | ||
|
||
# 최대 면적 구하기 | ||
max_area = 0 | ||
for x_i in range(1, len(x_cut_points)): | ||
for y_i in range(1, len(y_cut_points)): | ||
[x1, y1] = [x_cut_points[x_i-1], y_cut_points[y_i-1]] | ||
[x2, y2] = [x_cut_points[x_i], y_cut_points[y_i]] | ||
|
||
area = (x2 - x1) * (y2 - y1) | ||
|
||
# print("(%d, %d) ~ (%d, %d) = %d"%(x1, y1, x2, y2, area)) | ||
|
||
if(area > max_area): | ||
max_area = area | ||
|
||
|
||
print(max_area) |