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

19931번 - Finding Routers 서브태스크다국어언어 제한함수 구현

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB163311915.323%

문제

There is a street of length $l$ meters stretching from left to right, with $n$ small routers occupying various distinct positions along it. The origin is defined to be the leftmost point of the street. The routers are labelled 0ドル$ to $n-1$ from left to right, and router $i$ is placed $p[i]$ meters away from the origin.

It is guaranteed that router 0ドル$ is at the origin, and the distance in meters from each router to the origin is an even integer.

You wish to find out the position of each of the $n$ routers. As the routers are very small and difficult to spot from afar, you've decided to use the following procedure to find them:

  • Place a detector on a spot that is $x$ meters away from the origin,
  • Use the detector to find the label of the router closest to it. If there are two routers that are the same distance away from it, it will respond with the router with the smaller label.

You are allowed to use the detector at most $q$ times. Devise a strategy to find the positions of all the routers.

구현

You should implement the following procedure:

int[] find_routers(int l, int n, int q)
  • $l$: length of the street in meters.
  • $n$: number of routers.
  • $q$: maximum number of times the detector can be used.
  • This procedure will be called exactly once by the grader.
  • It should return an array $p$ indicating the positions of each router, with $p[i]$ being the distance between router $x$ and the origin.

The above procedure can make calls to the following procedure:

int use_detector(int x)
  • $x$: distance between the detector and the origin.
  • $x$ must be at least 0ドル$ and at most $l$.
  • This procedure will return the label of the router closest to the detector. If there are two routers that are the same distance away from it, it will return the smaller label.
  • This procedure may be called no more than $q$ times.

입력

출력

제한

  • $p[0]=0$
  • 0ドル \leq p[i] \leq l$ and $p[i]$ is even. (for all 0ドル \leq i \leq n-1$)
  • $p[i] < p[i+1]$ (for all 0ドル \leq i \leq n-2$)

예시 1

Consider the following call:

find_routers(5, 2, 10)

There are 2ドル$ routers on a street of length 5ドル$ meters and you are allowed at most 10ドル$ calls to use_detector. Suppose the routers are placed at 0ドル$ and 4ドル$ meters away from the origin respectively.

The find_routers procedure may choose to call use_detector(3), which returns 1ドル,ドル as router 1ドル$ at position 4ドル$ is closest to the detector.

The find_routers procedure may then choose to call use_detector(2), which returns 0ドル,ドル as both routers 0ドル$ and 1ドル$ are the same distance away from the detector and router 0ドル$ has a smaller label.

At this point, there is sufficient information to conclude that the routers are at positions 0ドル$ and 4ドル$ respectively.

As such, the find_routers procedure should return [0ドル,ドル 4ドル$].

예시 2

Consider the following call:

find_routers(6, 3, 10)

There are 3ドル$ routers on a street of length 6ドル$ meters and you are allowed at most 10ドル$ calls to use_detector. Suppose the routers are placed at 0ドル,ドル 2ドル$ and 6ドル$ meters away from the origin respectively.

The find_routers procedure may choose to call use_detector(5), which returns 2ドル$ as router 2ドル$ is at position 6ドル$ and therefore is the closest to the detector.

The find_routers procedure may then choose to call use_detector(4), which returns 1ドル,ドル as routers 1ドル$ and 2ドル$ are an equal distance away from the detector.

At this point, there is sufficient information to conclude that the routers are at positions 0ドル,ドル 2ドル$ and 6ドル$ respectively.

As such, the find_routers procedure should return [0ドル,ドル 2ドル,ドル 6ドル$].

서브태스크

번호배점제한
116

$l = 100\;000,ドル $n = 2,ドル $q = 100\;001$

221

$l = 100\;000,ドル $n = 100,ドル $q = 100\;001$

323

$l = 100\;000,ドル $n = 2,ドル $q = 20$

440

$l = 100\;000,ドル $n = 1000,ドル $q = 20\;000$

힌트

첨부

출처

Olympiad > International Olympiad in Informatics > IOI 2021 > Practice 4번

Olympiad > International Olympiad in Informatics > IOI 2020 > Practice 3번

제출할 수 있는 언어

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 によって変換されたページ (->オリジナル) /