https://www.acmicpc.net/problem/2477
문제풀이
import sys
input=sys.stdin.readline
K=int(input())
total=[]
width = []
height=[]
for _ in range(0,6):
dir,length=map(int,input().split())
if dir ==1 or dir == 2:
width.append(length)
total.append(length)
else:
height.append(length)
total.append(length)
big= max(height) * max(width)
maxheight_id=total.index(max(height))
maxwidth_id=total.index(max(width))
small1= abs(total[maxheight_id-1]-total[( maxheight_id-5 if maxheight_id==5 else maxheight_id+1)])
small2 =abs(total[maxwidth_id-1]-total[( maxwidth_id-5 if maxwidth_id==5 else maxwidth_id+1)])
result=big-small1*small2
print(result*K)
정리
큰 사각형 - 작은 사각형
제일 긴 세로 전후 가로의 차이와 제일 긴 가로 전후 세로의 차이를 구한 후 그 둘을 곱해서 작은 사각형의 넓이를 구한다.
제일 긴 세로 혹은 가로의 인덱스가 5일 경우 다음 인덱스를 구할 수 없으므로 조건문을 이용하여 인덱스의 -5를 취한 후 전후 길이를 구한다. 차이가 음수가 나올 수 있으므로 절대값을 취해준다.
[maxheight_id-1]은 제일 긴 세로의 직전 길이를 나타내고 [maxheight_id-5] 또는 [maxheight_id+1] 은 제일 긴 세로의 직후 길이를 나타낸다. 이 내용은 가로에도 동일하게 적용된다.
'코딩테스트 > 백준' 카테고리의 다른 글
[백준] #1213 팰린드롬 만들기 (python) (0) | 2024.05.04 |
---|---|
[백준] #17413 단어 뒤집기2 (python) (0) | 2024.04.30 |
[백준] #18111 마인크래프트 (python) (0) | 2024.04.29 |
[백준] #2108 통계학 (python) (0) | 2024.04.27 |
[백준] #14501 퇴사 (python) (0) | 2024.04.21 |