luogu#P16367. [OOI 2026] Cutting the Cake

    ID: 16546 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>交互题Special Judge2026Moscow Olympiad

[OOI 2026] Cutting the Cake

Problem Description

$\textbf{This problem can only be solved in the C++ programming language.}$

The organizers of the Closed Olympiad for school students in programming decided to order a large cake for the evening banquet. They ordered a cake with nn candles numbered from 00 to n1n-1. It is known that the candles are located at different points on the plane, no three candles lie on the same line, and no four candles form a trapezoid (a quadrilateral with two parallel sides).

To ensure that everyone gets a piece of cake, the organizers want to pre-construct a way to cut the cake into the maximum number of pieces. Unfortunately, you do not know the positions of the candles on the cake, and the only way to find out what the cake looks like is by corresponding with the pastry shop via email.

In one message, you can request to weigh no more than four triangular pieces, with vertices at the candles:

  • You provide two lists of triangles left\texttt{left} and right\texttt{right}, containing no more than four triangles in total. The triangles may intersect, share common candles, and even coincide.
  • The pastry shop will cut the triangular pieces according to the requested lists from several copies of the cake and place the pieces from left\texttt{left} on the left scale and the pieces from right\texttt{right} on the right scale.
  • You will receive the result of the weighing. We will consider that the weight of a piece equals its area. As a result, you will find out which of the triangle lists has a greater total area, or if the areas are equal.

After several weighings, you must find a way to cut the cake. Each piece must be a convex polygon with vertices at the candles. The vertices of the piece must be listed in the order of traversal either clockwise or counterclockwise. Any two pieces must not intersect at internal points. You must return a list of pieces whose total area is maximally possible. Also, in some groups, it is required to maximize the number of pieces.

Solution Format

This is an unusual problem. It has a testing format with a grader, where you need to implement only the function solve\texttt{solve} with the solution. This function will be called by the testing program of the jury (the grader), and the return value of the function will be accepted as the solution to the problem.

In particular, this means that the code you submit must not contain input or output\textbf{must not contain input or output}. Your code must not\textbf{must not} contain a main\texttt{main} function. If necessary, you can implement any number of helper functions, structures, classes, and global variables, but all the code of your solution must be in one file.

You must implement the following function:

std::vector<std::vector<int>> solve(int n);

The function solve\texttt{solve} takes a single integer nn --- the number of candles.

In the implementation of the function solve\texttt{solve}, you can use the function compare\texttt{compare}, which is implemented by the grader:

int compare(const std::vector<Triangle>& left, const std::vector<Triangle>& right);

This function takes two non-empty lists of triangles with a total size of no more than 44. It returns 1-1 if the total area of the triangles in left\texttt{left} is less than the total area of the triangles in right\texttt{right}, 00 if the areas are equal, and 11 otherwise. If an incorrect request is made or the limit on the number of requests is exhausted, the program will terminate automatically.

To access the function compare\texttt{compare} in your solution, the first line of your code must include the header file with the following line:

#include "triangles.h"

In this file, the structure Triangle\texttt{Triangle} used in the function compare\texttt{compare} is defined as follows:

struct Triangle {
    int i, j, k;

    Triangle() = default;
    Triangle(int i_, int j_, int k_) : i(i_), j(j_), k(k_) {}
};

This structure describes a single triangular piece, where the parameters i\texttt{i}, j\texttt{j}, and k\texttt{k} describe the indices of the candles that form the vertices of the triangular piece. The indices of the candles must be distinct for a single triangular piece, but they can repeat in multiple triangles.

$\textbf{You do not need to include the definition of the structure Triangle in the code you submit; it will be automatically taken from the header file.}$

All parameters (indices of candles in requests, as well as in the result you return) are specified in 0-indexing\textbf{0-indexing}.

Your function solve\texttt{solve} should use calls to the function compare\texttt{compare} to find any partitioning of the cake into convex pieces, where any two pieces do not intersect at internal points, the total area of the pieces is maximized, and possibly the number of pieces is maximized.

The function solve\texttt{solve} should return a list of pieces into which the cake is divided. Each piece is described by a structure std::vector<int>\texttt{std::vector<int>}, consisting of the candles that form the convex polygon. The candles must be listed in $\textbf{the order of traversal along the boundary of the polygon}$ (either clockwise or counterclockwise). Any two pieces must not intersect at internal points. You must return a list of pieces whose total area is maximally possible, and in some groups, it is additionally required to maximize the number of pieces while maintaining the condition of maximizing the total area.

During one run of the grader, the $\textbf{jury will make exactly one call to the function}$ solve\texttt{solve}. The grader is not adaptive\textbf{grader is not adaptive}, meaning that the positions of the candles are fixed in advance and do not depend on the implementation of the function solve\texttt{solve}.

Testing

You are provided with a solution template triangles.cpp\texttt{triangles.cpp}, as well as a header file triangles.h\texttt{triangles.h}, containing the definitions of the functions solve\texttt{solve} and compare\texttt{compare}. For convenience in testing, you are provided with a grader --- the file grader.cpp\texttt{grader.cpp}. This file implements reading input data from the standard input stream, calling the function solve\texttt{solve}, and outputting the result of the function solve\texttt{solve} to the standard output stream. In the testing system, the grader may differ.

To compile your code triangles.cpp\texttt{triangles.cpp} in C++, use the command

g++ -std=c++20 grader.cpp triangles.cpp -o grader

After executing this command, an executable file of the grader grader\texttt{grader} or grader.exe\texttt{grader.exe} will be created, depending on your operating system, which you can run to input tests in the specified format.

If compilation via commands causes you difficulties, for local testing, you can copy the implementation of the function solve\texttt{solve} into the file grader.cpp\texttt{grader.cpp} (it must be inserted before the function main\texttt{main}) and run the file grader.cpp\texttt{grader.cpp}. In this case, before submitting the solution to the testing system, you will need to leave only the implementation of the function solve\texttt{solve}, $\textbf{remembering to include the header file at the beginning of the code}$ (this is done by adding the line #include "triangles.h"\texttt{\#include "triangles.h"} at the beginning of the code you submit). If you are using any C++ libraries, their inclusion must also be added at the beginning of the submitted code.

In case of receiving a compilation error verdict, ensure that $\textbf{the code you submit does not contain a main function, nor does it contain definitions of the function compare and the structure Triangle}$. You can only use the function compare\texttt{compare} and the structure Triangle\texttt{Triangle} in the code you submit.

Input Format

The grader reads the test in the following format:

The first line contains an integer nn (4n100004 \leq n \leq 10\,000) --- the number of candles.

In the next nn lines, there are two integers xix_i, yiy_i (109xi,yi109-10^9 \leq x_i, y_i \leq 10^9) --- the coordinates of the ii-th candle.

Output Format

The grader outputs the results of the function solve\texttt{solve} --- the list of found pieces.

In the first line, the number of found polygons (the size of the vector returned by the function solve\texttt{solve}) is printed.

In the following lines for each polygon (an element in the vector returned by the function solve\texttt{solve}), the size of the polygon is printed first, followed by the line of indices of the candles that are the vertices of the polygon (elements of each std::vector<int>\texttt{std::vector<int>} in the return value of the function solve\texttt{solve}). Each polygon must be convex, and its vertices must be listed in the order of traversal (either clockwise or counterclockwise). No two polygons should intersect at internal points.

In the file grader.cpp\texttt{grader.cpp}, there is a variable verbose\texttt{verbose}, which is initially set to 00. By increasing its value, the grader will write more detailed information about your solution and its requests.

4
1 2
1 4
0 0
3 -1
3
3
0 1 2
3
0 2 3
3
0 1 3
5
-1 -1
4 4
4 -2
1 2
-2 2
1
4
0 4 1 2
6
2 2
0 -2
-1 3
-2 0
7 0
2 -3
4
3
2 4 3
3
3 4 5
3
1 3 5
3
0 2 4

Hint

Note

In the first example, a possible sequence of function calls could look like this:

Initially, the function solve(4)\texttt{solve(4)} is called.

From the function solve\texttt{solve}, the function

compare({Triangle(0, 1, 2)}, {Triangle(1, 2, 3)}) 

is called.

During the execution of the function, the sizes of the triangular pieces formed by the triangle with vertices at candles numbered 00, 11, and 22 and the triangle with vertices at candles 11, 22, and 33 are compared.

Since the first triangle is smaller than the second, the function returns 1-1.

Next, from the function solve\texttt{solve}, the function

compare({Triangle(1, 2, 3)}, {Triangle(0, 1, 2), Triangle(0, 1, 3)}) 

is called.

The response will return 11, as the area of the triangle with vertices at candles 11, 22, and 33 is greater than the total area of the triangle with vertices at candles 00, 11, and 22 and the triangle with vertices at candles 00, 11, and 33.

Next, from the function solve\texttt{solve}, the function

compare({Triangle(1, 2, 3)}, {Triangle(0, 1, 2), Triangle(2, 3, 0), Triangle(0, 1, 3)}) 

is called.

The response will return 00.

In the end, the function solve\texttt{solve} returns {{0,1,2},{0,2,3},{0,1,3}}\tt{\{\{0, 1, 2\}, \{0, 2, 3\}, \{0, 1, 3\}\}} --- a description of the partitioning of the cake into convex pieces that have the maximum possible total area and do not intersect at internal points.

In the first and third examples, the found method of cutting the cake has the maximum possible number of pieces, so such answers would be considered correct in groups with maximization. In the second test, the number of pieces is not maximally possible, so such an answer would be considered correct in groups without maximization, but would receive 00 points in groups with maximization.

Note that the first test fits the additional constraints of groups 11 and 22, while the third test fits the additional constraints of group 55.

Scoring

The tests for this problem consist of 11 groups. The rules by which points are awarded for groups are described below. Note that passing the tests from the statement is not required for some groups. The final score for each group is equal to the maximum score obtained for that group of tests across all submissions.

The score for a solution for a group of tests is equal to the minimum score obtained across all tests in the group.

  • If your solution makes an incorrect call to compare\texttt{compare} or returns an answer that does not satisfy the mandatory conditions, it will receive 00 points for the test.
  • In each test, your solution is allowed to make no more than 21062 \cdot 10^6 calls to the function compare\texttt{compare}. If the limit is exceeded, your solution will receive 00 points for the test.
  • In some groups, it is required to maximize the number of pieces in the answer. In such groups, if the number of pieces is not maximally possible, your solution will receive 00 points for the test.

If none of the described conditions for the test are violated, the answer for the test is considered correct. Let the full score for the group of tests be pp. Some groups are evaluated using a formula, while others are evaluated without using a formula:

  • If the group is evaluated without using a formula, the score for the test is equal to pp.
  • Otherwise, if the group is evaluated using a formula, let qq be the number of calls to compare\texttt{compare} made by your solution. Then the score for the test is equal to
$$\left\lfloor p \cdot \frac{20n}{\max{(q, 20n)}} \right\rfloor$$
Group Full score Score < Additional constraints Required groups Comments
Max. Formula nn
00 no no -- -- Tests from the statement.
11 1313 n=4n = 4
22 44 yes 11
33 1313 no -- -- (109,109)(10^9, -10^9), (109,109)(-10^9, 10^9), (109,109)(10^9, 10^9) are in the set, the rest are random points inside this triangle
44 88 yes 33
55 1111 yes -- points are the vertices of a convex polygon
66 99 no no n100n \leq 100 random points
77 88 yes 66
88 99 no yes --
99 88 yes
1010 99 no
1111 88 yes

In groups 6--9, all points were chosen randomly and independently from the square [109,109]×[109,109][-10^9, 10^9] \times [-10^9, 10^9].

In groups 3--4, points other than (109,109)(10^9, -10^9), (109,109)(-10^9, 10^9), (109,109)(10^9, 10^9) were chosen randomly and independently from the triangle with vertices (109,109)(10^9, -10^9), (109,109)(-10^9, 10^9), (109,109)(10^9, 10^9).

In these groups, among such random tests, only those where all points are distinct, no three lie on the same line, and no four form a trapezoid are retained.