import sys
input=sys.stdin.readline
x,y,w,s=map(int,input().split())
if 2*w<s:
print((x+y)*w)
else:
if w>=s:
temp = max(x,y)*s
if (x+y)%2!=0:
temp+=(w-s)
print(temp)
else:
print(min(x,y)*s+((x-min(x,y)+y-min(x,y))*w))
주어진 테스트 케이스를 유심히 보지 않았다. 뒤늦게 분석하니 이해가 안됐다.
힌트를 조금 얻어 진행했다..
2 0 12 10
에 대해 조금 듣고 해보니 이해가 겨우 됐다..
이런 감각은 어디서 얻는 거지
#백준 1459(걷기)
x, y, w, s = map(int, input().split()) #집의 위치(x, y), 평행, 대각선
#평행 이동
move1 = (x + y) * w
#짝수, 홀수에 따른 이동
if (x + y) % 2 == 0:
#x + y가 짝수라면
move2 = max(x, y) * s
else:
#홀수라면
move2 = (max(x, y) - 1) * s + w
#대각선 + 평행 이동
move3 = (min(x, y) * s) + ((max(x, y) - min(x, y)) * w)
res = min(min(move1, move2), move3)
print(res)
모든 경우에 대해 계산하여 min을 찾은 것 같다.
출처
X, Y, W, S = map(int, input().split())
X, Y = min(X, Y), max(X, Y)
if S < W*2:
s, b = min(X, Y), max(X, Y)
if S <= W:
m = (X+Y)%2
print((Y-m)*S + m*W)
else:
print(X*S + (Y-X)*W)
else:
print((X+Y)*W)
###########
X, Y, W, S = map(int, input().split())
X, Y = min(X, Y), max(X, Y)
m = (X+Y)%2
print(min((X+Y)*W, X*S + (Y-X)*W, (Y-m)*S + m*W))