Logo
(追記) (追記ここまで)

34679번 - Docking Day 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB80382340.351%

문제

A space station has docking ports labeled by distinct positive integers 1,ドル 2, 3, \dots$ arranged in a straight line. Port 1ドル$ is the leftmost, and the line extends infinitely to the right. Three labeled ships—Red ($R$), Green ($G$), and Blue ($B$)—are currently at different ports. Due to maintenance, traffic control must re-dock the three ships to newly assigned target ports. To keep clear sight lines and safe spacing during re-docking, the moving ship must pass over exactly one other ship—no more, no less. Specifically, traffic control wants to re-dock while satisfying these constraints:

  1. Each ship must end at its own target port.
  2. At any time, no two ships may occupy the same port.
  3. In one move, choose one ship and place it on an empty port so that exactly one of the other two ships has a port strictly between the old and new ports.

For example, suppose $R,ドル $G,ドル and $B$ are currently at ports 3ドル,ドル 4ドル,ドル 8ドル$ and their target ports are 3ドル,ドル 2ドル,ドル 10ドル,ドル respectively. In three moves - (1) move $G$ from 4ドル$ to 9ドル$ (passing $B$), (2) move $B$ from 8ドル$ to 10ドル$ (passing $G$), and (3) move $G$ from 9ドル$ to 2ドル$ (passing $R$) - all three ships reach their targets. See the figures below.

Given the current ports and target ports of the three ships, write a program to compute the minimum number of moves required to re-dock them to the target ports.

입력

Your program is to read from standard input. The input starts with a line containing three distinct integers, $r_1,ドル $g_1$ and $b_1$ (1ドル ≤ r_1, g_1, b_1 ≤ 10^6$), which denote the positions of the current ports of $R,ドル $G,ドル and $B,ドル respectively. The following line contains three distinct integers, $r_2,ドル $g_2$ and $b_2$ (1ドル ≤ r_2, g_2, b_2 ≤ 10^6$), which denote the positions of the target ports of $R,ドル $G,ドル and $B,ドル respectively.

출력

Your program is to write to standard output. Print exactly one line. The line should contain the minimum number of moves required to re-dock them to the target ports.

제한

예제 입력 1

3 4 8
3 2 10

예제 출력 1

3

예제 입력 2

3 4 5
6 2 1

예제 출력 2

3

노트

출처

ICPC > Regionals > Asia Pacific > Korea > Nationwide Internet Competition > Seoul Nationalwide Internet Competition 2025 C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /