| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 163 | 31 | 19 | 15.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:
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)
The above procedure can make calls to the following procedure:
int use_detector(int x)
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ドル$].
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ドル$].
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 16 | $l = 100\;000,ドル $n = 2,ドル $q = 100\;001$ |
| 2 | 21 | $l = 100\;000,ドル $n = 100,ドル $q = 100\;001$ |
| 3 | 23 | $l = 100\;000,ドル $n = 2,ドル $q = 20$ |
| 4 | 40 | $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)