#P16454. [APIO 2026] Scallion Pancake Party
[APIO 2026] Scallion Pancake Party
题目描述
Bohan is hosting a party. Since he loves scallion pancakes, he decides to buy them from the store nearby for his party. The store sells different flavors of scallion pancakes, numbered from 0 to . Bohan decides to buy scallion pancakes of each flavor, for a total of scallion pancakes. Each scallion pancake is divided into identical slices before put into its own bag. The bags are numbered from 0 to . Let denote the scallion pancake flavor for bag .
During the party, Bohan invites all guests to play a game. The game proceeds as follows.
First, Bohan picks guests and brings them to rooms numbered , , \cdots, such that each room has exactly one guest. The remaining guests stay outside until the end of the game. All rooms look exactly the same, so the guests cannot tell which room they are in.
Next, for each room (), Bohan enters room and secretly tells the guest an integer , representing a forbidden flavor. He may or may not also tell the guest which room they are in. Bohan guarantees that is a permutation of .
Then, there are rounds. In the -th round, Bohan brings bags , , \cdots, one by one in the sequential order into room . When the guest in room receives bag , they learn:
- , the scallion pancake flavor that bag contains, and
- the number of slices remaining in the bag.
Before receiving the next bag, the guest in room must decide how many slices to eat from the current bag. The number of slices they can eat depends on the situation:
- If , the guest can remove any number of slices from the bag and eat them.
- If , the guest is not allowed to eat any slices.
Note that the guests do not know the sequence in advance.
After all rounds, the guests outside are given the sequence of bags. Upon seeing the bags, they learn the scallion pancake flavors and the number of slices left in each bag. With this information, they must determine the values of .
The guests are allowed to communicate before the game starts. They also know the values of and in advance. Your goal is to implement a strategy so that the guests outside can always correctly determine the values of .
Implementation details
You need to implement three procedures.
You should implement the following two procedures for guests in rooms .
void init(int N, int K, int p, int r)
Suppose the guest is in room .
- : the number of scallion pancake flavors.
- : the number of slices of each scallion pancake before the game starts.
- : the forbidden flavor to eat in room .
- If Bohan decides to tell the guest which room they're in, then . Otherwise, .
int strategy(int b, int f, int s)
Suppose the guest is in room .
- : the current bag number.
- : the scallion pancake flavor for bag .
- : the number of slices left in bag .
- This procedure should return a non-negative integer , representing the number of slices the guest decides to eat.
- If , then must hold.
- If , then must hold.
You should implement the following procedure for the guests outside.
std::vector<int> guess(int N, int K, std::vector<int> F, std::vector<int> S)
- : the number of scallion pancake flavors.
- : the number of slices of each scallion pancake before the game starts.
- : an array of length where is the flavor of the scallion pancake in bag .
- : an array of length where is the number of slices remaining in bag after all rounds.
- This procedure should return an array of length where is the number given to the guest in room .
Each test case involves independent games.
During the judging process, for each of the games, there will be processes. For each such that , process represents the guest in room . Process represents the guests outside. For each such that , process starts after process finishes.
For processes 0 to :
initis called exactly once.strategyis called times afterinit.- It is guaranteed that for the -th call, .
For process :
guessis called exactly once.
The judge may interleave processes from different games, but it is guaranteed that the relative order of processes within each individual game is preserved.
输入格式
The sample grader only supports one game per test case.
Input format:
N K
P[0] P[1] ... P[N-1]
F[0] F[1] ... F[N*N-1]
reveal
revealis either or .- If
revealis , the grader will act as if Bohan tells no one their room number. - If
revealis , the grader will act as if Bohan tells everyone their room number.
- If
输出格式
If the array returned by guess matches , the sample grader prints
Accepted
In addition, the grader prints the function calls made in order for debugging purposes.
提示
Example
Consider the situation in which and for the only game in the test case.
Let denote current number of slices remaining in bag . Initially, .
Suppose the guests determine the following strategy before the game starts.
- For guests in rooms, if they are allowed to eat the current scallion pancake:
- If the current scallion pancake is the first one they can eat, then they will eat all remaining slices.
- Otherwise, they will only eat one slice.
- For the guests outside:
- If , then they will guess that .
- Otherwise, they will guess that .
The game proceeds as follows.
First, the judge starts process representing the guest in room and calls init(2, 2, 1, -1). After initializing, the judge makes the following calls:
| Procedure call | Return value |
|---|---|
strategy(0, 1, 2) |
|
strategy(1, 0, 2) |
|
strategy(2, 0, 2) |
|
strategy(3, 1, 2) |
The first and fourth calls must return since .
After this process ends (round finishes), .
Next, the judge starts process representing the guest in room and calls init(2, 2, 0, -1). After initializing, the judge makes the following calls:
| Procedure call | Return value |
|---|---|
strategy(0, 1, 2) |
|
strategy(1, 0, 0) |
|
strategy(2, 0, 1) |
|
strategy(3, 1, 2) |
Note that the second and third calls must return since .
After this process ends (round finishes), .
Finally, the judge starts process representing the guests outside. The judge makes the following call:
| Procedure call | Return value |
|---|---|
guess(2, 2, [1, 0, 0, 1], [0, 0, 1, 1]) |
[1,0] |
The guests outside guessed the correct permutation. Thus, the test case is considered correct.
Note that this approach does not always make it possible for the guests outside to guess the permutation correctly.
The attachment package for this task contains a different sample input in addition to this example.
Constraints
- .
- .
- The sum of over all games in a test case doesn't exceed .
- .
- is a permutation of .
- for each such that .
- appears exactly times in for each such that .
- The judge is not adaptive, that is, and are fixed before the first call to
initis made.
Subtasks
| Subtask | Score | Additional Constraints |
|---|---|---|
| . | ||
| and Bohan decides to tell everyone which room they're in. | ||
| and $[F[i \cdot N], F[i \cdot N + 1], \cdots, F[i \cdot N + N - 1]]$ is a permutation of for each such that . | ||
| . | ||
| . | ||
| . |