1459 - 걷기

LeeKyoungChang·2022년 5월 13일
0

Algorithm

목록 보기
114/203
post-thumbnail

📚 1459 - 걷기

걷기

 

이해

✔️ 경우의 수

  • 평행 이동만 하는 경우
  • 짝수, 홀수에 따라 다른 이동을 하는 경우
  • 대각선, 평행 이동을 하는 경우

구체적으로 설명이 잘되어 있는 곳

 

소스

import sys  
  
read = sys.stdin.readline  
  
x, y, w, s = map(int, read().split())  
  
answer = (x + y) * w  # 평행 이동만 하는 경우

# 짝수, 홀수에 따라 다른 이동을 하는 경우
# 대각선 s를 활용한다.
if not (x + y) % 2:  
    answer = min(answer, max(x, y) * s)  
else:  
    answer = min(answer, (max(x, y) - 1) * s + w)  

# 대각선, 평행 이동을 하는 경우
answer = min(answer, min(x, y) * s + (max(x, y) - min(x, y)) * w)  
  
  
print(answer)

 

profile
"야, (오류 만났어?) 너두 (해결) 할 수 있어"

0개의 댓글