프로그램 명: ncpc_connect
제한시간: 1 초
When constructing electric circuits one has to connect pairs of points
using wire, preferable as short as possible. In this problem we have an
empty circuit board of size N * M where we want to connect the two
points A1 and A2 with each other using one wire, and the two points
B1 and B2 with each other using another wire.
The wires must go along the horizontal and vertical edges of the grid (see figure), and the
two wires may not share a common vertex. Determine the minimum
length of wire needed to do so. The wire may not go outside the circuit board.
입력
-
The first line contains two integers, N (2 <= N <= 100) and M (2 <= M <= 100), the grid
size of the circuit board.
-
Then follows four lines containing the coordinates for the points A1, A2, B1 and B2,
respectively. Each coordinate pair will be described using two integers and will correspond
to an intersection point in the grid. The first coordinate will be between 0 and N inclusive
and the second coordinate between 0 and M inclusive. All coordinate pairs will be unique.
출력
A single line containing the minimum length of wire needed to connect the points, or "IMPOSSIBLE" if it's not possible to do so.
입출력 예
입력
6 6
2 1
5 4
4 0
4 5
출력
15
입력
6 3
2 3
4 0
0 2
6 1
출력
IMPOSSIBLE
출처:ncpc/2010/Problem B
[질/답]
[제출 현황]
[푼 후(0)]