$O(1)$
방법은 세가지 중 하나이다.
1. 대각선으로 가다가 축에 평행하게 가기
2. 축에 평행하게만 가기
3. 대각선으로만 가기, 도착지까지 한 칸 남으면 축에 평행하게 가기
#include<cstdio> #include<algorithm> using namespace std; long long x, y, w, s; int main() { scanf("%lld%lld%lld%lld", &x, &y, &w, &s); if (x < y) swap(x, y); printf("%lld", min({ (x + y)*w, (x - y)*w + y*s,x*s + (x - y) % 2 * (w - s) })); return 0; }
댓글 없음 :
댓글 쓰기