You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This discussion was converted from issue #47 on September 15, 2026 10:47.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://atcoder.jp/contests/abc178/tasks/abc178_e
Problem Summary
x, y 좌표가 주어질 때 가장 먼 맨해튼 거리를 구하는 문제.
Solution
일단 유명한 문제라고 하는데... 처음 대회에서는 풀지 못했다...
다시 천천히 해보면 어렵지 않은 문제이긴 하다
먼저 조건을 잘 써보면,
| xi - xj | + | yi - yj |의 최댓값을 찾는 문제인데 절댓값을 벗겨준 후 정리해줄 수 있다.(xi - xj) + (yi - yj)
(xi + yi) - (xj + yj)
-(xi - xj) + (yi - yj)
-(xi - yi) + (xj - yj)
(xi - xj) - (yi - yj)
(xi - yi) - (xj - yj)
-(xi - xj) - (yi - yj)
-(xi + yi) + (xj + yj)
잘 보면 양쪽이 (xj + yj) 또는 (xj - yj) 형식으로 정리가 되는데 x, y값의 합 또는 x, y의 값의 차를 전부 구하고 그중에 최대가 되도록 해주면 된다.
따라서 정답은
max( max(xi + yi) - min(xi + yi), max(xi - yi) - min(xi - yi) )Source Code
All reactions