#P9311. [EGOI 2021] Twin Cookies / 姐妹分饼干
[EGOI 2021] Twin Cookies / 姐妹分饼干
Background
Day 1 Problem C.
The statement is translated from EGOI2021 twincookies.
The official statement does not provide an interaction library. Due to implementation reasons of the interaction library, the testdata may be relatively weak. If you can write an adaptive interaction library, you may contact rui_er.
Problem Description
This is an I/O interactive problem.
Sophie is preparing her sisters' birthday party. They all like cookies. This year, they want to try something new: cookies made by the Unique Cookie Taste Company (UCTC), which produces cookies with different flavors.
Each cookie produced by UCTC has an integer tastiness between and . The sisters will be jealous of each other, so the total tastiness of the cookies each sister receives must be the same.
UCTC only accepts orders of exactly cookies. In each order, the customer specifies the tastiness of each cookie they want.
As the name suggests, the Unique Cookie Taste Company refuses to produce two cookies with the same tastiness for the same customer. Sophie must ensure that she never orders the same tastiness twice, whether within one order or across different orders. Sophie has never ordered from UCTC before, so she can buy each tastiness at most once.
There is one more obstacle for Sophie: it is well known that UCTC's delivery service is extremely bad. When a customer orders cookies, only one of them will be delivered. The rest are eaten by the delivery staff. The customer cannot decide which cookie will be delivered.
Since the birthday is approaching, Sophie only has time to place at most orders. Your task is to help her.
More specifically, you need to do the following:
-
First, order cookies. You can place at most orders, each containing exactly desired tastiness values. You may place multiple orders. Right after each order is sent, you immediately learn the tastiness of the cookie that gets delivered.
Remember that you cannot order the same tastiness more than once, even across different orders. (In particular, if you ordered some tastiness values but they were not delivered, you still cannot order the same tastiness again.)
-
Then, share cookies. When you have received enough cookies, you should give the sisters some cookies. Each person should receive at least one cookie, and the total tastiness of the cookies each person receives should be the same. You do not have to distribute all delivered cookies.
Output Format
After each output of your program, you must flush the output stream. This is necessary to ensure the interaction library receives your output immediately.
Some examples:
- In C++, there are several options:
fflush(stdout);std::cout << std::flush;std::cout << std::endl;(note that this prints a newline)- Reading from
std::cinwill also flush the output stream.
- In Java, you can use
System.out.flush(). - In Python, you can use
sys.stdout.flush().
Interaction
Your program should perform the following operations:
- Read from standard input.
- Up to times:
-
First, print one line to standard output describing an order of cookies.
-
Then, read the tastiness of the delivered cookie.
It is guaranteed that this number is among the tastiness values in the current order.
-
- Output three lines describing a way to distribute some cookies to the sisters.
The interaction library will write one integer per line.
To order cookies, output one line starting with ? followed by integers: the tastiness values of the cookies you order. Print a space before each integer.
Remember that you can place at most orders, and you are not allowed to order the same tastiness value more than once.
When you have received enough cookies, output the final three lines describing the distribution method.
The first line should be ! m k, where : the numbers of cookies given to the first and second person, respectively.
The second line contains positive integers separated by spaces: the tastiness values of the cookies received by the first person.
The third line contains positive integers separated by spaces: the tastiness values of the cookies received by the second person.
Your output must satisfy the following requirements:
- Each person receives at least one cookie.
- The total tastiness received by each person is the same.
- You can only use delivered cookies.
- Each cookie can be assigned to at most one person.
Any output that satisfies the requirements will be judged AC. In particular, you may output the selected cookies in any order.
After you output the final three lines, flush the output stream one last time and terminate your program normally.
1
13
7
31
12
5
3
? 13
? 7
? 31
? 12
? 5
? 3
! 2 3
7 13
12 5 3
2
7
2
5
? 3 7
? 2 8
? 1 5
! 2 1
2 5
7
Hint
Hint
The sample input and output should be read line by line. Your program alternates between reading one integer from standard input and printing one line to standard output (or the final three lines).
The interaction library chooses the delivered cookie arbitrarily. This means that in some test points, the interaction library may be adaptive; but in other test points, it may choose randomly. In particular, for , if you output the same orders as in sample , you may get different results.
Constraints
For all data, .
- Subtask 1 ( points): .
- Subtask 2 ( points): .
- Subtask 3 ( points): .
- Subtask 4 ( points): .
- Subtask 5 ( points): .
- Subtask 6 ( points): no special restrictions.
Translated by ChatGPT 5