benchmarks.wiki / Public workspace
Humanity's Last Code Exam / 2019_F / Directing Rainfall
Problem
Answer published by the source. Consult the official source to check your work against its answer.
platform
atcoder
question content
## Problem Statement
Porto and the nearby Douro Valley are famous for producing port wine. Wine lovers from all over the world come here to enjoy this sweet wine where it is made. The International Consortium of Port Connoisseurs (ICPC) is organizing tours to the vineyards that are upstream on the Douro River. To make visits more pleasurable for tourists, the ICPC has recently installed sun tarps above the vineyards. The tarps protect tourists from sunburn when strolling among the vines and sipping on a vintage port.
Unfortunately, there is a small problem with the tarps. Grapes need sunlight and water to grow. While the tarps let through enough sunlight, they are entirely waterproof. This means that rainwater might not reach the vineyards below. If nothing is done, this year’s wine harvest is in peril!
The ICPC wants to solve their problem by puncturing the tarps so that they let rainwater through to the vineyards below. Since there is little time to waste before the rainy season starts, the ICPC wants to make the minimum number of punctures that achieve this goal.
We will consider a two-dimensional version of this problem. The vineyard to be watered is an interval on the x-axis, and the tarps are modeled as line segments above the x-axis. The tarps are slanted, that is, not parallel to the x- or y-axes. Rain falls straight down from infinitely high. When any rain falls on a tarp, it flows toward the tarp’s lower end and falls off from there, unless there is a puncture between the place where the rain falls and the tarp’s lower end—in which case the rain will fall through the puncture instead. After the rain falls off a tarp, it continues to fall vertically. This repeats until the rain hits the ground (the x-axis).
For legal reasons, you have to ensure that at least some of the rain that reaches the vineyard originated from directly above the vineyard. This is to prevent any vineyard from stealing all their rain from neighboring vineyards.
### Input
The first line of input contains three integers `l`, `r`, and `n`, where is the interval representing the vineyard and is the number of tarps. Each of the following lines describes a tarp and contains four integers , where is the position of the tarp’s lower end and is the position of the higher end .
The x-coordinates given in the input are all distinct. The tarps described in the input will not intersect, and no endpoint of a tarp will lie on another tarp.
### Output
Output the smallest number of punctures that need to be made to get some rain falling from above the vineyard to the vineyard.
### Sample Input 1
Plain-text mathematical notation (without MathML)
## Problem Statement Porto and the nearby Douro Valley are famous for producing port wine. Wine lovers from all over the world come here to enjoy this sweet wine where it is made. The International Consortium of Port Connoisseurs (ICPC) is organizing tours to the vineyards that are upstream on the Douro River. To make visits more pleasurable for tourists, the ICPC has recently installed sun tarps above the vineyards. The tarps protect tourists from sunburn when strolling among the vines and sipping on a vintage port. Unfortunately, there is a small problem with the tarps. Grapes need sunlight and water to grow. While the tarps let through enough sunlight, they are entirely waterproof. This means that rainwater might not reach the vineyards below. If nothing is done, this year’s wine harvest is in peril! The ICPC wants to solve their problem by puncturing the tarps so that they let rainwater through to the vineyards below. Since there is little time to waste before the rainy season starts, the ICPC wants to make the minimum number of punctures that achieve this goal. We will consider a two-dimensional version of this problem. The vineyard to be watered is an interval on the x-axis, and the tarps are modeled as line segments above the x-axis. The tarps are slanted, that is, not parallel to the x- or y-axes. Rain falls straight down from infinitely high. When any rain falls on a tarp, it flows toward the tarp’s lower end and falls off from there, unless there is a puncture between the place where the rain falls and the tarp’s lower end—in which case the rain will fall through the puncture instead. After the rain falls off a tarp, it continues to fall vertically. This repeats until the rain hits the ground (the x-axis). For legal reasons, you have to ensure that at least some of the rain that reaches the vineyard originated from directly above the vineyard. This is to prevent any vineyard from stealing all their rain from neighboring vineyards. ### Input The first line of input contains three integers `l`, `r`, and `n`, where (l,r) (0≤l<r≤10⁹) is the interval representing the vineyard and n (0≤n≤5×10⁵) is the number of tarps. Each of the following n lines describes a tarp and contains four integers x₁,y₁,x₂,y₂, where (x₁,y₁) is the position of the tarp’s lower end and (x₂,y₂) is the position of the higher end (0≤x₁,x₂≤10⁹,x₁≠x₂,and 0<y₁<y₂≤10⁹). The x-coordinates given in the input (l,r,and the values of x₁ and x₂ for all tarps) are all distinct. The tarps described in the input will not intersect, and no endpoint of a tarp will lie on another tarp. ### Output Output the smallest number of punctures that need to be made to get some rain falling from above the vineyard to the vineyard. ### Sample Input 1
Original LaTeX notation
## Problem Statement
Porto and the nearby Douro Valley are famous for producing port wine. Wine lovers from all over the world come here to enjoy this sweet wine where it is made. The International Consortium of Port Connoisseurs (ICPC) is organizing tours to the vineyards that are upstream on the Douro River. To make visits more pleasurable for tourists, the ICPC has recently installed sun tarps above the vineyards. The tarps protect tourists from sunburn when strolling among the vines and sipping on a vintage port.
Unfortunately, there is a small problem with the tarps. Grapes need sunlight and water to grow. While the tarps let through enough sunlight, they are entirely waterproof. This means that rainwater might not reach the vineyards below. If nothing is done, this year’s wine harvest is in peril!
The ICPC wants to solve their problem by puncturing the tarps so that they let rainwater through to the vineyards below. Since there is little time to waste before the rainy season starts, the ICPC wants to make the minimum number of punctures that achieve this goal.
We will consider a two-dimensional version of this problem. The vineyard to be watered is an interval on the x-axis, and the tarps are modeled as line segments above the x-axis. The tarps are slanted, that is, not parallel to the x- or y-axes. Rain falls straight down from infinitely high. When any rain falls on a tarp, it flows toward the tarp’s lower end and falls off from there, unless there is a puncture between the place where the rain falls and the tarp’s lower end—in which case the rain will fall through the puncture instead. After the rain falls off a tarp, it continues to fall vertically. This repeats until the rain hits the ground (the x-axis).
For legal reasons, you have to ensure that at least some of the rain that reaches the vineyard originated from directly above the vineyard. This is to prevent any vineyard from stealing all their rain from neighboring vineyards.
### Input
The first line of input contains three integers `l`, `r`, and `n`, where \((l, r)\) \((0 \leq l < r \leq 10^9)\) is the interval representing the vineyard and \(n\) \((0 \leq n \leq 5 \times 10^5)\) is the number of tarps. Each of the following \(n\) lines describes a tarp and contains four integers \(x_1, y_1, x_2, y_2\), where \((x_1, y_1)\) is the position of the tarp’s lower end and \((x_2, y_2)\) is the position of the higher end \((0 \leq x_1, x_2 \leq 10^9, x_1 \neq x_2, \text{and } 0 < y_1 < y_2 \leq 10^9)\).
The x-coordinates given in the input \((l, r, \text{and the values of } x_1 \text{ and } x_2 \text{ for all tarps})\) are all distinct. The tarps described in the input will not intersect, and no endpoint of a tarp will lie on another tarp.
### Output
Output the smallest number of punctures that need to be made to get some rain falling from above the vineyard to the vineyard.
### Sample Input 1
Code
10 20 5
32 50 12 60
30 60 8 70
25 70 0 80
15 30 28 40
5 20 14 25
### Sample Output 1
Code
2
### Sample Input 2
Code
2 4 2
3 2 0 3
5 2 1 5
### Sample Output 2
Code
1
question title
Directing Rainfall
Discussion
No discussion posts on this page yet. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.
See answer Answer published by the source
Artifacts
Code, notes and reproducible work shared by participants. Files are served from a separate origin.
No artifacts on this page yet. Share reproducible code or notes in a contribution. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.
Source and history
initial import