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

20077번 - Wiring 서브태스크다국어언어 제한함수 구현

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB25211410945.992%

문제

Maryam is an electrical engineer. She is designing wiring on a communication tower. On the tower there are some connection points, placed at distinct heights. A wire can be used to connect any two connection points. Each connection point can be connected to an arbitrary number of wires. There are two types of connection points: red and blue.

For the purpose of this problem the tower should be viewed as a line and the connection points as blue and red points that are at non-negative integer coordinates on this line. The length of a wire is the distance between the two connection points it connects.

Your goal is to help Maryam find a wiring scheme such that:

  1. Each connection point has at least one wire to a connection point of a different color.
  2. The total length of the wires is minimized.

구현

You should implement the following procedure:

int64 min_total_length(int[] r, int[] b)
  • $r$: array of length $n$ containing the positions of the red connection points in increasing order.
  • $b$: array of length $m$ containing the positions of the blue connection points in increasing order.
  • This procedure should return the minimum total length of wires, among all valid wiring schemes.
  • Note that the return type of this procedure is int64.

예시

min_total_length([1, 2, 3, 7], [0, 4, 5, 9, 10])

The figure below illustrates this example.

  • The tower is shown horizontally.
  • In the black-and-white printed version of the problem statement the red connection points are dark and the blue ones are light.
  • There are 4ドル$ red connection points, located at positions 1,ドル 2, 3,$ and 7ドル$.
  • There are 5ドル$ blue connection points, located at positions 0,ドル 4, 5, 9,$ and 10ドル$.
  • One optimal solution is shown in the figure above.
  • In this solution, the total length of the wires is 1ドル + 2 +たす 2 +たす 2 +たす 3 = 10,ドル which is optimal. So, the procedure should return 10ドル$.
  • Note that two wires are connected to the connection point at position 7ドル$.

입력

출력

제한

  • 1ドル \leq n, m \leq 100,000円,ドル
  • 0ドル \leq r[i] \leq 10^9$ (for all 0ドル \leq i \leq n-1$),
  • 0ドル \leq b[i] \leq 10^9$ (for all 0ドル \leq i \leq m-1$),
  • Each of the arrays $r$ and $b$ is sorted in ascending order.
  • All $n+m$ values in the arrays $r$ and $b$ are distinct.

서브태스크

번호배점제한
17

$n, m \leq 200$

213

All red connection points have positions smaller than any blue connection points.

310

There is at least one red connection point and one blue connection point among every 7ドル$ consecutive connection points.

425

All connection points have different positions in the range $[1, n+m]$.

545

No additional constraints.

힌트

샘플 그레이더

The sample grader reads the input in the following format:

  • line 1ドル$: $\;\; n \;\; m$
  • line 2ドル$: $\;\; r[0] \;\; r[1] \; \ldots \; r[n-1]$
  • line 3ドル$: $\;\; b[0] \;\; b[1] \; \ldots \; b[m-1]$

The sample grader prints a single line containing the return value of min_total_length.

출처

Olympiad > International Olympiad in Informatics > IOI 2017 > Day 1 2번

  • 문제를 만든 사람: Aleksandar Ilić

제출할 수 있는 언어

C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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