| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 194 | 32 | 29 | 19.728% |
The IOI 2023 organizers are in big trouble! They forgot to plan the trip to Ópusztaszer for the upcoming day. But maybe it is not yet too late ...
There are $N$ landmarks at Ópusztaszer indexed from 0ドル$ to $N-1$. Some pairs of these landmarks are connected by bidirectional roads. Each pair of landmarks is connected by at most one road. The organizers don't know which landmarks are connected by roads.
We say that the density of the road network at Ópusztaszer is at least $\delta$ if every 3ドル$ distinct landmarks have at least $\delta$ roads among them. In other words, for each triplet of landmarks $(u, v, w)$ such that 0ドル \le u \lt v \lt w \lt N,ドル among the pairs of landmarks $(u,v), (v,w)$ and $(u,w)$ at least $\delta$ pairs are connected by a road.
The organizers know a positive integer $D$ such that the density of the road network is at least $D$. Note that the value of $D$ cannot be greater than 3ドル$.
The organizers can make calls to the phone dispatcher at Ópusztaszer to gather information about the road connections between certain landmarks. In each call, two nonempty arrays of landmarks $[A[0], \ldots, A[P-1]]$ and $[B[0], \ldots, B[R-1]]$ must be specified. The landmarks must be pairwise distinct, that is,
For each call, the dispatcher reports whether there is a road connecting a landmark from $A$ and a landmark from $B$. More precisely, the dispatcher iterates over all pairs $i$ and $j$ such that 0ドル \le i \lt P$ and 0ドル\le j \lt R$. If, for any of them, the landmarks $A[i]$ and $B[j]$ are connected by a road, the dispatcher returns true. Otherwise, the dispatcher returns false.
A trip of length $l$ is a sequence of distinct landmarks $t[0], t[1], \ldots, t[l-1],ドル where for each $i$ between 0ドル$ and $l-2,ドル inclusive, landmark $t[i]$ and landmark $t[i+1]$ are connected by a road. A trip of length $l$ is called a longest trip if there does not exist any trip of length at least $l+1$.
Your task is to help the organizers to find a longest trip at Ópusztaszer by making calls to the dispatcher.
You should implement the following procedure:
int[] longest_trip(int N, int D)
The above procedure can make calls to the following procedure:
bool are_connected(int[] A, int[] B)
true if there is a landmark from $A$ and a landmark from $B$ connected by a road. Otherwise, it returns false.longest_trip, and at most 150ドル,000円$ times in total.The grader is not adaptive. Each submission is graded on the same set of test cases. That is, the values of $N$ and $D,ドル as well as the pairs of landmarks connected by roads, are fixed for each call of longest_trip within each test case.
Consider a scenario in which $N = 5,ドル $D = 1,ドル and the road connections are as shown in the following figure:
The procedure longest_trip is called in the following way:
longest_trip(5, 1)
The procedure may make calls to are_connected as follows.
| Call | Pairs connected by a road | Return value |
|---|---|---|
are_connected([0], [1, 2, 4, 3]) |
$(0,1)$ and $(0,2)$ | true |
are_connected([2], [0]) |
$(2,0)$ | true |
are_connected([2], [3]) |
$(2,3)$ | true |
are_connected([1, 0], [4, 3]) |
none | false |
After the fourth call, it turns out that none of the pairs $(1,4),ドル $(0,4),ドル $(1,3)$ and $(0,3)$ is connected by a road. As the density of the network is at least $D = 1,ドル we see that from the triplet $(0, 3, 4),ドル the pair $(3,4)$ must be connected by a road. Similarly to this, landmarks 0ドル$ and 1ドル$ must be connected.
At this point, it can be concluded that $t = [1, 0, 2, 3, 4]$ is a trip of length 5ドル,ドル and that there does not exist a trip of length greater than 5ドル$. Therefore, the procedure longest_trip may return $[1, 0, 2, 3, 4]$.
Consider another scenario in which $N = 4,ドル $D = 1,ドル and the roads between the landmarks are as shown in the following figure:
The procedure longest_trip is called in the following way:
longest_trip(4, 1)
In this scenario, the length of a longest trip is 2ドル$. Therefore, after a few calls to procedure are_connected, the procedure longest_trip may return one of $[0, 1],ドル $[1, 0],ドル $[2, 3]$ or $[3, 2]$.
Subtask 0 contains an additional example test case with $N=256$ landmarks. This test case is included in the attachment package that you can download from the contest system.
longest_trip does not exceed 1ドル,024円$ in each test case.| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 5 | $D = 3$ |
| 2 | 10 | $D = 2$ |
| 3 | 25 | $D = 1$. Let $l^\star$ denote the length of a longest trip. Procedure 'longest_trip' does not have to return a trip of length $l^\star$. Instead, it should return a trip of length at least $\left\lceil \frac{l^\star}{2} \right\rceil$. |
| 4 | 60 | $D = 1$ |
In subtask 4 your score is determined based on the number of calls to procedure are_connected over a single invocation of longest_trip. Let $q$ be the maximum number of calls among all invocations of longest_trip over every test case of the subtask. Your score for this subtask is calculated according to the following table:
| Condition | Points |
|---|---|
| 2ドル,750円 \lt q \le 32,640円$ | 20ドル$ |
| 550ドル \lt q \le 2,750円$ | 30ドル$ |
| 400ドル \lt q \le 550$ | 45ドル$ |
| $q \le 400$ | 60ドル$ |
If, in any of the test cases, the calls to the procedure are_connected do not conform to the constraints described in Implementation Details, or the array returned by longest_trip is incorrect, the score of your solution for that subtask will be 0ドル$.
Let $C$ denote the number of scenarios, that is, the number of calls to longest_trip. The sample grader reads the input in the following format:
The descriptions of $C$ scenarios follow.
The sample grader reads the description of each scenario in the following format:
Here, each $U_i$ (1ドル \le i \lt N$) is an array of size $i,ドル describing which pairs of landmarks are connected by a road. For each $i$ and $j$ such that 1ドル \le i \lt N$ and 0ドル \le j \lt i$:
In each scenario, before calling longest_trip, the sample grader checks whether the density of the road network is at least $D$. If this condition is not met, it prints the message Insufficient Density and terminates.
If the sample grader detects a protocol violation, the output of the sample grader is Protocol Violation: <MSG>, where <MSG>is one of the following error messages:
invalid array: in a call to are_connected, at least one of arrays $A$ and $B$
non-disjoint arrays: in a call to are_connected, arrays $A$ and $B$ are not disjoint.too many calls: the number of calls made to are_connected exceeds 32ドル,640円$ over the current invocation of longest trip, or exceeds 150ドル,000円$ in total.too many elements: the total number of landmarks passed to are_connected over all calls exceeds 1ドル,500円,000円$.Otherwise, let the elements of the array returned by longest_trip in a scenario be $t[0], t[1], \ldots, t[l - 1]$ for some nonnegative $l$. The sample grader prints three lines for this scenario in the following format:
are_connected over this scenarioFinally, the sample grader prints:
are_connected over all calls to longest_tripOlympiad > International Olympiad in Informatics > IOI 2023 > Day 1 2번
C++17, C++20, C++17 (Clang), C++20 (Clang)