#P9514. [JOI Open 2023] 花园 / Garden
[JOI Open 2023] 花园 / Garden
Background
Translated from JOI Open 2023 T3 “庭園 / Garden”.
Problem Description
The JOI Kingdom is a mysterious kingdom with a vast territory. King JOI is the king of the JOI Kingdom, and he is planning to split off part of the territory to build his garden.
The JOI network can be regarded as a sufficiently large 2D grid, tiled by square cells from top to bottom and from left to right. One cell is the origin. Let denote the cell reached by moving cells to the right from the origin, and then moving cells up. Here, moving cells to the left means moving cells to the right. Similarly, moving cells downward means moving cells upward.
There are some artworks in the territory. These artworks are divided into Type A and Type B according to how they are placed in the territory.
- There are kinds of Type A artworks. The -th kind of artwork () is placed in every cell of the form , where are integers.
- There are kinds of Type B artworks. The -th kind of artwork () is placed in every cell of the form (where are integers) or (where are integers).
Note that a single cell may contain multiple artworks of different kinds.
King JOI plans to choose a rectangular region on the grid to build the garden. In other words, he chooses four integers . Then the cells form King JOI’s garden, where are integers satisfying . Since King JOI likes to see many kinds of artworks, for each of the kinds of artworks, the garden must contain at least one artwork of that kind. On the other hand, if the garden is too large, the citizens of the JOI Kingdom will get angry. Therefore, King JOI wants to minimize the number of cells contained in the garden while satisfying the above condition.
Given the information about the artworks, write a program to compute the minimum number of cells contained in King JOI’s garden.
Input Format
The first line contains three integers .
The next lines each contain two integers .
The next lines each contain two integers .
Output Format
Output one integer in a single line, representing the minimum number of cells contained in King JOI’s garden.
2 1 5
1 4
2 2
0 0
8
3 4 100
20 26
81 56
20 3
58 71
74 82
95 61
95 61
2840
5 7 5000
1046 365
4122 1166
4009 2896
1815 4065
4372 1651
2382 123
1475 836
3313 4005
2579 568
4300 4867
1050 3214
3589 4653
10543092
Hint
[Sample Explanation #1]
The figure below shows the cells in the JOI Kingdom’s territory satisfying .

In the figure, circles and diamonds represent Type A and Type B artworks, respectively. The integer inside each circle or diamond indicates the kind index of the artwork. If King JOI chooses , then King JOI’s garden is the black rectangular region. In this case, for these three kinds of artworks, King JOI’s garden contains at least one of each kind. The number of cells in the garden is . Since there is no smaller garden that satisfies the condition, output .
This sample satisfies the constraints of all subtasks.
[Sample Explanation #2]
This sample satisfies the constraints of subtasks .
[Sample Explanation #3]
This sample satisfies the constraints of subtasks .
[Constraints]
For all testdata, it holds that:
The additional constraints and scores for the subtasks are shown in the table below.
| Subtask | Additional Constraints | Score |
|---|---|---|
| No additional constraints |
Translated by ChatGPT 5