시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 1024 MB | 137 | 20 | 15 | 12.712% |
Pak Dengklek lives in Indonesia, a country consisting of $N$ towns numbered from $0$ to $N - 1$. For every pair of towns, there is a one-way road going from one town to the other. Pak Dengklek has no information on the direction of the roads, but Pak Chanek has offered to help him
Pak Dengklek is allowed to ask Pak Chanek at most $40\,000$ questions. For each question in turn, Pak Dengklek chooses a pair of towns and Pak Chanek tells him the direction of the road connecting those two towns.
Pak Dengklek wants to know a town number with at most one outgoing road, or report if there is no such town. If there is more than one such town, Pak Dengklek only needs to know any of such town numbers.
You should implement the following procedure:
int find_town(int N)
The above procedure can make calls to the following procedure:
bool check_road(int A, int B)
true
if there is a road going from town $A$ to town $B$ and returns false
if there is a road going from town $B$ to town $A$.Consider a scenario in which there are $3$ towns and the roads connecting the towns are illustrated by the following image:
The procedure find_town
is called in the following way:
find_town(3)
This procedure may call check_road(0, 1)
, which (in this scenario) returns true
. At this point, there is sufficient information to conclude that town $1$ has at most one outgoing road. Therefore, the procedure may return $1$.
Additionally, this procedure may call check_road(2, 1)
, which (in this scenario) returns false
. At this point, there is sufficient information to conclude that town $2$ has at most one outgoing road. Therefore, the procedure may also return $2$.
Consider a scenario in which there are $5$ towns and the roads connecting the towns are illustrated by the following image:
The procedure find_town
is called in the following way:
find_town(5)
In this scenario, there is no town with at most one outgoing road. Therefore, the procedure should return $-1$.
번호 | 배점 | 제한 |
---|---|---|
1 | 10 | $N ≤ 250$ |
2 | 90 | No additional constraints. |
In subtask 2 you can obtain a partial score. Let $Q$ be the maximum number of calls to the procedure check_road
across all test cases in this subtask. Your score for this subtask is calculated according to the following table:
Condition | Points |
---|---|
$20\,000 < Q ≤ 40\,000$ | $20$ |
$8000 < Q ≤ 20\,000$ | $90 - 70\sqrt{\frac{Q - 8000}{12000}}$ |
$Q ≤ 8000$ | $90$ |
In some test cases, the behaviour of the grader is adaptive. This means that in these test cases the grader does not have a fixed configuration of road directions. Instead, the answers given by the grader may depend on the questions asked by your solution. It is guaranteed that the grader answers in such a way that after each answer there is at least one configuration of road directions consistent with all the answers given so far.
The sample grader reads an array $R$ of $N$ strings with $N$ characters representing the roads in Indonesia. For each $i$ and $j$ such that $0 ≤ i, j ≤ N - 1$ ($i ≠ j$), $R[i][j]$ is $1$ if there is a road going from town $i$ to town $j$ and $R[i][j]$ is $0$ if there is a road going from town $j$ to town $i$. For each $i$ such that $0 ≤ i ≤ N - 1$, $R[i][i]$ should be $0$.
The sample grader reads input in the following format:
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:
too many questions
: check_road
is called more than $40\,000$ times.invalid parameters
: check_road
is called with $A$ and $B$ are not distinct integers from $0$ to $N - 1$ inclusive.Otherwise, the output of the sample grader is in the following format:
find_town
.check_road
.Note that the sample grader is not adaptive.
C++17, C++20, C++17 (Clang), C++20 (Clang)