benchmarks.wiki / Public workspace

Humanity's Last Code Exam / 2019_B / Beautiful Bridges

Problem

Answer published by the source. Consult the official source to check your work against its answer.

platform

atcoder

question content

## Problem: Arch Bridges Construction ### Description What connects us all? Well, it is often bridges. Since ancient times, people have been building bridges for roads, for trains, for pedestrians, and as aqueducts to transport water. It is humanity’s way of not taking inconvenient geography for an answer. The company Arch Bridges Construction (ABC) specializes in—you guessed it—the construction of arch bridges. This classical style of bridge is supported by pillars that extend from the ground below the bridge. Arches between pillars distribute the bridge’s weight onto the adjacent pillars. The bridges built by ABC often have pillars spaced at irregular intervals. For aesthetic reasons, ABC’s bridges always have semicircular arches. However, while a bridge arch can touch the ground, it cannot extend below the ground. This makes some pillar placements impossible. Given a ground profile and a desired bridge height h h , there are usually many ways of building an arch bridge. We model the ground profile as a piecewise-linear function described by n n key points (x1,y1),(x2,y2),,(xn,yn)(x_1, y_1), (x_2, y_2), \ldots, (x_n, y_n), where the x-coordinate of a point is the position along the bridge, and the y-coordinate is the elevation of the ground above sea level at this position along the bridge. The first and last pillars must be built at the first and last key points, and any intermediate pillars can be built only at these key points. The cost of a bridge is the cost of its pillars (which is proportional to their heights) plus the cost of its arches (which is proportional to the amount of material used). So a bridge with k k pillars of heights h1,,hk h_1, \ldots, h_k that are separated by horizontal distances d1,,dk1 d_1, \ldots, d_{k-1} has a total cost of: αi=1khi+βi=1k1di2 \alpha \cdot \sum_{i=1}^{k} h_i + \beta \cdot \sum_{i=1}^{k-1} d_i^2 for some given constants α \alpha and β \beta . ABC wants to construct each bridge at the lowest possible cost. ### Input - The first line of input contains four integers n,h,α, n, h, \alpha, and β \beta , where 2n104 2 \leq n \leq 10^4 is the number of points describing the ground profile, 1h105 1 \leq h \leq 10^5 is the desired height of the bridge above sea level, and 1α,β104 1 \leq \alpha, \beta \leq 10^4 are the cost factors as described earlier. - Then follow n n lines, the i i -th of which contains two integers xi,yi x_i, y_i (0x1<x2<<xn105(0 \leq x_1 < x_2 < \ldots < x_n \leq 10^5 and 0yi<h) 0 \leq y_i < h), describing the ground profile. ### Output - Output the minimum cost of building a bridge from horizontal position x1 x_1 to xn x_n at height h h above sea level. If it is impossible to build any such bridge, output `impossible`. ### Sample Input 1
Plain-text mathematical notation (without MathML)
## Problem: Arch Bridges Construction

### Description

What connects us all? Well, it is often bridges. Since ancient times, people have been building bridges for roads, for trains, for pedestrians, and as aqueducts to transport water. It is humanity’s way of not taking inconvenient geography for an answer.

The company Arch Bridges Construction (ABC) specializes in—you guessed it—the construction of arch bridges. This classical style of bridge is supported by pillars that extend from the ground below the bridge. Arches between pillars distribute the bridge’s weight onto the adjacent pillars.

The bridges built by ABC often have pillars spaced at irregular intervals. For aesthetic reasons, ABC’s bridges always have semicircular arches. However, while a bridge arch can touch the ground, it cannot extend below the ground. This makes some pillar placements impossible.

Given a ground profile and a desired bridge height h, there are usually many ways of building an arch bridge. We model the ground profile as a piecewise-linear function described by n key points (x₁,y₁),(x₂,y₂),…,(x_(n),y_(n)), where the x-coordinate of a point is the position along the bridge, and the y-coordinate is the elevation of the ground above sea level at this position along the bridge. The first and last pillars must be built at the first and last key points, and any intermediate pillars can be built only at these key points.

The cost of a bridge is the cost of its pillars (which is proportional to their heights) plus the cost of its arches (which is proportional to the amount of material used). So a bridge with k pillars of heights h₁,…,h_(k) that are separated by horizontal distances d₁,…,d_(k−1) has a total cost of:

α⋅∑_(i=1)^(k)h_(i)+β⋅∑_(i=1)^(k−1)d_(i)²

for some given constants α and β. ABC wants to construct each bridge at the lowest possible cost.

### Input

- The first line of input contains four integers n,h,α, and β, where 2≤n≤10⁴ is the number of points describing the ground profile, 1≤h≤10⁵ is the desired height of the bridge above sea level, and 1≤α,β≤10⁴ are the cost factors as described earlier.
- Then follow n lines, the i-th of which contains two integers x_(i),y_(i) (0≤x₁<x₂<…<x_(n)≤10⁵ and 0≤y_(i)<h), describing the ground profile.

### Output

- Output the minimum cost of building a bridge from horizontal position x₁ to x_(n) at height h above sea level. If it is impossible to build any such bridge, output `impossible`.

### Sample Input 1

Original LaTeX notation
## Problem: Arch Bridges Construction

### Description

What connects us all? Well, it is often bridges. Since ancient times, people have been building bridges for roads, for trains, for pedestrians, and as aqueducts to transport water. It is humanity’s way of not taking inconvenient geography for an answer.

The company Arch Bridges Construction (ABC) specializes in—you guessed it—the construction of arch bridges. This classical style of bridge is supported by pillars that extend from the ground below the bridge. Arches between pillars distribute the bridge’s weight onto the adjacent pillars.

The bridges built by ABC often have pillars spaced at irregular intervals. For aesthetic reasons, ABC’s bridges always have semicircular arches. However, while a bridge arch can touch the ground, it cannot extend below the ground. This makes some pillar placements impossible.

Given a ground profile and a desired bridge height \( h \), there are usually many ways of building an arch bridge. We model the ground profile as a piecewise-linear function described by \( n \) key points \((x_1, y_1), (x_2, y_2), \ldots, (x_n, y_n)\), where the x-coordinate of a point is the position along the bridge, and the y-coordinate is the elevation of the ground above sea level at this position along the bridge. The first and last pillars must be built at the first and last key points, and any intermediate pillars can be built only at these key points.

The cost of a bridge is the cost of its pillars (which is proportional to their heights) plus the cost of its arches (which is proportional to the amount of material used). So a bridge with \( k \) pillars of heights \( h_1, \ldots, h_k \) that are separated by horizontal distances \( d_1, \ldots, d_{k-1} \) has a total cost of:

\[
\alpha \cdot \sum_{i=1}^{k} h_i + \beta \cdot \sum_{i=1}^{k-1} d_i^2
\]

for some given constants \( \alpha \) and \( \beta \). ABC wants to construct each bridge at the lowest possible cost.

### Input

- The first line of input contains four integers \( n, h, \alpha, \) and \( \beta \), where \( 2 \leq n \leq 10^4 \) is the number of points describing the ground profile, \( 1 \leq h \leq 10^5 \) is the desired height of the bridge above sea level, and \( 1 \leq \alpha, \beta \leq 10^4 \) are the cost factors as described earlier.
- Then follow \( n \) lines, the \( i \)-th of which contains two integers \( x_i, y_i \) \((0 \leq x_1 < x_2 < \ldots < x_n \leq 10^5 \) and \( 0 \leq y_i < h)\), describing the ground profile.

### Output

- Output the minimum cost of building a bridge from horizontal position \( x_1 \) to \( x_n \) at height \( h \) above sea level. If it is impossible to build any such bridge, output `impossible`.

### Sample Input 1

Code

5 60 18 2
0 0
20 20
30 10
50 30
70 20

### Sample Output 1

Code

6460

### Sample Input 2

Code

4 10 1 1
0 0
1 9
9 9
10 0

### Sample Output 2

Code

impossible

question title

Beautiful Bridges

Discussion

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

Official source

initial import