Logo
(追記) (追記ここまで)

34275번 - SLA Tomography 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB20151575.000%

문제

Stereolithography (SLA) is a 3D printing technique for hardening liquid material into a solid object one layer at a time using a laser. In this problem, we will consider a 2D simplification of SLA where the design of the object being printed can be represented as a rectangular grid of '\#' and '.' characters, where '\#' represents a grid cell occupied by the object and '.' is empty space. For example, here is a 4ドル\times 8$ design:

..#.....
..#..#..
#.#.##..
#.#####.

A design does not have to consist of a single connected piece, but except for '\#' cells on the bottom row of the design, each '\#' cell must be supported by another '\#' cell directly below it.

Printing an object using SLA proceeds layer-by-layer, starting from the bottom row. First, all cells in the row are flooded with a liquid photosensitive resin. Then a laser sweeps over the row, hardening the resin in all '\#' cells into a solid and skipping all '.' cells. Then, leftover liquid to the left of the leftmost '\#' and to the right of the rightmost '\#' drains away. Other liquid remains trapped. (If there are no '\#' cells in the row---which can only happen for rows near the top of the design, after the object has been fully printed---all liquid drains away from the row.) This process then repeats for each subsequent row. For the design above, after printing is complete, resin remains trapped in all of the cells marked with a '$\sim$' character below:

..#.....
..# #..
# # ##..
# #####.

While manually suctioning the leftover resin from the object, you start to wonder: how much of the original design can be recovered from knowing only how much liquid resin is left over in each row of the design after printing? For the above design, the amount of leftover resin in each row (starting from the top of the design) is 0ドル,ドル 2ドル,ドル 2ドル,ドル 1ドル$. Other designs also have the same leftover-resin fingerprint; for example:

....
#..#
#..#
#.##

Given a list of how many cells of liquid resin are left over in each row (starting from the top row), print the width of the narrowest object design whose rows would contain those amounts of liquid resin after printing. If no such design exists, print impossible.

입력

The first line of input contains a single integer $N (1 \leq N \leq 10^5),ドル the number of rows in the object design. $N$ lines follow, each containing a single integer $x$ (0ドル \leq x \leq 10^9$), the number of cells of leftover liquid resin in each row of the desired object design (in order from top to bottom).

At least one row will have at least one leftover cell of liquid resin.

출력

Print the width (number of columns) in the narrowest object design whose number of leftover liquid resin cells in each row matches the input. ("Narrowest" means having the smallest possible number of columns). If no such design exists, print impossible instead.

제한

예제 입력 1

4
0
2
2
1

예제 출력 1

4

Sample Input 1 corresponds to the example above.

예제 입력 2

3
4
0
4

예제 출력 2

11

One narrowest-possible design for Sample Input 2 is:

#....#.....
######.....
######....#

힌트

출처

ICPC > Regionals > North America > North America Championship > North America Championship 2025 K번

  • 문제를 만든 사람: Mark Sturtevant
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /