|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|2 초||512 MB||16||11||11||73.333%|
Our satellite has just discovered an alien civilization on a remote planet. We have already obtained a low-resolution photo of a square area of the planet. The photo shows many signs of intelligent life. Our experts have identified n points of interest in the photo. The points are numbered from 0 to n - 1. We now want to take high-resolution photos that contain all of those n points.
Internally, the satellite has divided the area of the low-resolution photo into an m by m grid of unit square cells. Both rows and columns of the grid are consecutively numbered from 0 to m - 1 (from the top and left, respectively). We use (s, t) to denote the cell in row s and column t. The point number i is located in the cell (ri, ci). Each cell may contain an arbitrary number of these points.
Our satellite is on a stable orbit that passes directly over the main diagonal of the grid. The main diagonal is the line segment that connects the top left and the bottom right corner of the grid. The satellite can take a high-resolution photo of any area that satisfies the following constraints:
The satellite is able to take at most high-resolution photos. Once the satellite is done taking photos, it will transmit the high-resolution photo of each photographed cell to our home base (regardless of whether that cell contains some points of interest). The data for each photographed cell will only be transmitted once, even if the cell was photographed several times.
Thus, we have to choose at most k square areas that will be photographed, assuring that:
Your task is to find the smallest possible total number of photographed cells.
You should implement the following function (method):
int64 take_photos(int n, int m, int k, int r, int c)
n: the number of points of interest,
m: the number of rows (and also columns) in the grid,
k: the maximum number of photos the satellite can take,
c: two arrays of length n describing the coordinates of the grid cells that contain points of interest. For 0 ≤ i ≤ n - 1 , the i-th point of interest is located in the cell
Please use the provided template files for details of implementation in your programming language.
take_photos(5, 7, 2, [0, 4, 4, 4, 4], [3, 4, 6, 5, 6])
In this example we have 7 × 7 a grid with 5 points of interest. The points of interest are located in four different cells: (0, 3), (4, 4), (4, 5) and (4, 6). You may take at most 2 high-resolution photos.
One way to capture all five points of interest is to make two photos: a photo of the 6 × 6 square containing the cells (0, 0) and (5, 5), and a photo of the 3 × 3 square containing the cells (4, 4) and (6, 6). If the satellite takes these two photos, it will transmit the data about 41 cells. This amount is not optimal.
The optimal solution uses one photo to capture the 4 × 4 square containing cells (0, 0) and (3, 3) and another photo to capture the 3 × 3 square containing cells (4, 4) and (6, 6). This results in only 25 photographed cells, which is optimal, so take_photos should return 25.
Note that it is sufficient to photograph the cell (4, 6) once, even though it contains two points of interest.
This example is shown in the figures below. The leftmost figure shows the grid that corresponds to this example. The middle figure shows the suboptimal solution in which 41 cells were photographed. The rightmost figure shows the optimal solution.
take_photos(2, 6, 2, [1, 4], [4, 1])
Here we have 2 points of interest located symmetrically: in the cells (1, 4) and (4, 1). Any valid photo that contains one of them contains the other one as well. Therefore, it is sufficient to use a single photo.
The figures below show this example and its optimal solution. In this solution the satellite captures a single photo of 16 cells.
For all subtasks, 1 ≤ k ≤ n.
1 ≤ n ≤ 50, 1 ≤ m ≤ 100, k = n
1 ≤ n ≤ 500, 1 ≤ m ≤ 1,000, for all i such that 0 ≤ i ≤ n - 1, ri = ci
1 ≤ n ≤ 500, 1 ≤ m ≤ 1,000
1 ≤ n ≤ 4,000, 1 ≤ m ≤ 1,000,000
1 ≤ n ≤ 500,000, 1 ≤ k ≤ 100, 1 ≤ m ≤ 1,000,000
1 ≤ n ≤ 500,000, 1 ≤ m ≤ 1,000,000
The sample grader reads the input in the following format:
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)