Waiter, waiter, another polyprotic buffer please!
Oh no! Little IR12661 has a midterm tomorrow for his Principles of Chemical Science class. It's been anguishing him for the entirety of the past month, and it's all coming to a climax tonight (different timezone), as he's having a horrible nightmare about a weak acid, a strong base, and the paper he has due in twelve hours walking into a bar. Please, help him wake up so he can start his first draft before it's too late.
We are dealing with an all-you-can-eat restaurant with only four characters: Acid and Base --- the two customers; Zotero --- the chef; and of course the robotic waiter.
It is known that the menu lists dishes and that the customers have very different preferences when it comes to food (naturally). We can therefore establish the preferences as a set and its complement, with Acid preferring all foods from and Base preferring all foods from . It is guaranteed that .
The way these two customers can order food works as follows: every ten minutes, the waiter arbitrarily (see implementation details) chooses a customer to take their order. The customer can then reply with a single menu item from their preference list, or say that they don't want anything right now. The waiter takes the order to the kitchen, reporting it to Zotero, and then performs this cycle again.
Note that Acid and Base are in the same room so they can hear each other's order.
It turns out that Acid, Base, and Zotero were good friends back in the day, but they are now imprisoned in the restaurant by the waiter, who won't let them go until the chef, Zotero, figures out the customers' preferences. In this spirit, it is Acid's and Base's job to make certain orders to the waiter, whenever they have the opportunity, in order to communicate to Zotero enough information so that he can deduce their individual preferences. Since Zotero hasn't taken chemistry and can't understand these subtleties, it is sufficient that he reports either or .
Task
Your task is to establish a strategy that would help the characters escape from the restaurant as fast as possible. Additionally, because acids and bases are not really all that different, the two customers should have the same behaviour (i.e. you should implement a strategy specific to the chef role and one specific for the customer role regardless of whether the customer is Acid or Base).
Implementation details
This is a communication task. The grader will instantiate three separate instances of your code, which should implement both the strategy for the chef and for the customers. Your program must not read from standard input or write to standard output. You must include the header waiter.h and implement the following functions without implementing a main function:
void initChef(int N);
std::vector<int> getOrder(int x);
void initCustomer(int N, int k, std::vector<int> S);
int makeOrder();
void waitTurn(int x);
The function initChef is called exactly once in the instance corresponding to the chef. It is passed , the count of menu items. The function should not return anything.
The function getOrder is called once for each order made by either customer. It is passed , an integer which is either (encoding silence) or between and . The return protocol is as follows:
- The function should return an
emptyC++vector if the chef has determined that more orders need to be made before he makes a decision. - The function should return a
non-emptyC++vector when the chef has been able to determine the preferences, that is either or , the vector itself containing the elements of either set.
The function initCustomer is called once in each of the two instances corresponding to the customers. It is passed , the count of menu items; , the count of items preferred by the current customer; and , a C++ vector containing the preferred items of that customer. The function should not return anything.
The function makeOrder is called every time an order should be placed in exactly one of the customer instances. The other customer instance will have a waitTurn call shortly thereafter. The function makeOrder is not passed any values, and it must either return (in case the customer wishes not to order anything) or a value from the customer's set.
The function waitTurn is called after an order is placed by the other customer instance. It is passed a value which is the order placed by the other customer. The function should not return anything.
Note that the two processes corresponding to the customers do not know which process corresponds to Acid and which one corresponds to Base.
The committee's grader is adaptive in terms of which customer instance has its makeOrder function called and which other instance has its waitTurn function called. It is, however, not adaptive in terms of selecting the set .
Scoring
Your solution will be graded on 15 sets of tests with similar properties. For each of these sets, we set a constant as the target number of queries to solve that set. Let be the largest number of queries performed by your solution on any test in the set. If your solution fails a test in the set or , it receives no points for the set. If it passes all tests in the set and , it receives full points for the set.
For a set solved with , let and define

The score on the set is , where is the assigned score of the set.
Knowing that is the number of items on the menu, let . The test sets are as follows.
Restrictions
| # | Points | Restrictions |
|---|---|---|
| 0 | 0 | Exemple. |
| 1 | 6 | , , |
| 2 | 4 | , , |
| 3 | 4 | , , |
| 4 | 7 | , , |
| 5 | 4 | , , |
| 6 | 5 | , , |
| 7 | 4 | , , |
| 8 | 4 | , , |
| 9 | 4 | , , |
| 10 | 4 | , , |
| 11 | 4 | , , |
| 12 | 4 | , , |
| 13 | 15 | , , |
| 14 | 15 | , , |
| 15 | 16 | , , |
Sample grader and testing tool
You are provided with a testing_tool.py together with a sample_grader.cpp to help you emulate the interaction on your computer. We strongly encourage you to use them.
In order to run the testing tool, add it to a folder together with sample_grader.cpp and your implementation. Let us assume that your source file is called sol.cpp.
Afterwards, you should open a terminal in this folder; for the provided IDEs (VS Code and CLion) this can be done from inside the editor using the help functionality or, on Linux, you can right click in the folder and choose "Open in Terminal". In that terminal, write the following line (and press "Enter"):
python3 testing_tool.py sol.cpp test.txt
Note that for this command, if your source code has a different name, you should replace sol.cpp with the appropriate name.
In this case we also assume that the input for the testing tool is found in a file called test.txt. The format of said file should be:
- line : --- the number of dishes in the menu;
- line : --- the number of dishes that customer A prefers;
- line : --- the set of dishes preferred by customer A;
- line : an arbitrary length string containing A's and B's, the order in which the waiter should take the customers' orders.
You can find more detailed instructions on how to run the testing tool in the comments at the beginning of the file.
The sample grader can either act as the chef or as a customer and call the appropriate function from your implementation.
To run the sample grader as the chef instance, you should provide the input in the following format:
- line :
chef--- the word "chef"; - line : --- the number of dishes in the menu.
Then you should interact with it according to the responses you receive from the customers. For each interaction, the grader calls the getOrder function and, if it returns a non-empty vector, that vector will be output and the program stops.
To run the sample grader as a customer instance, you should provide the input in the following format:
- line :
customer--- the word "customer"; - line : --- the number of dishes in the menu and the number of preferred dishes of that customer;
- line : --- the set of preferred dishes of that customer. Note that you should run two such instances that receive their respective sets.
Then you should interact with it according to the statement. For each turn until the chef instance outputs an answer, you should choose which customer process to ask for their order and send the answer to both the chef and the other customer. When asking the customer for their order, you should input !. When informing it of the other customer's order, you should send . followed by the order placed.
Examples
Let us assume the testing tool receives the following input:
6
2
3 6
BABBABABBBAAA
and that set corresponds to one of the customers (let's call him ), and the opposite set corresponds to the other customer (let's call him ).

The answer in the end is correct and the testing tool will print a message in that regard.