#Algorithm
문제 번호
18111번 마인크래프트(S2)
알고리즘 + 이론
브루트포스 알고리즘
정답 코드
# 18111번
# 1. 인벤토리 블록으로 가장 높은 땅 높이에 맞추기
# 2. 높이 -1 하고 시간도 더하고
# 3. 높이 -1 하고 시간도 더하고
N, M, B = map(int,input().split())
temp = B
land = [list(map(int,input().split())) for _ in range(N)]
h = max(max(row) for row in land)
result = [float('inf'),0]
while True:
time = 0
B = temp
for i in range(N):
for j in range(M):
block = h - land[i][j]
if block == 0:
continue
elif block > 0:
time += block
B -= block
else:
time += abs(block)*2
B += abs(block)
if B < 0:
if h == 0:
break
else:
h -= 1
continue
if result[0] > time:
result[0] = time
result[1] = h
if h == 0:
break
else:
h -= 1
print(result[0], result[1])
느낀점 & 피드백
과연 브루트포스인가? 풀면서 확신이 늦게 들었던 것 같고 꼼꼼하게 예외처리 하는 부분이 오래걸리는 것 같다.
이 글이 도움이 되셨나요?