| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 2048 MB | 4 | 4 | 4 | 100.000% |
Skyscrapers is a grid logic puzzle in which numbers from 1ドル$ to $n$ have to be placed into an $n\times n$ grid. Each number needs to appear exactly once in each row and column. These numbers are to be thought of as skyscrapers which are the respective number of units tall. The rows and columns may have clue numbers on either end which describe the number of visible skyscrapers when looking down that row or column from that position, where taller buildings block the view of any shorter buildings behind them.
Figure K.1: Illustration of Sample Output 1. Two buildings (1 and 5) are visible from the left and two buildings (4 and 5) are visible from the right.
In this problem we consider only a single row of a Skyscrapers grid which has clue numbers on both ends. Find out whether it is possible to place the skyscrapers from 1ドル$ to $n$ in this row to satisfy both clues, and if so, find a valid placement.
The input consists of:
If a valid placement exists, output "yes", followed by $n$ distinct integers $h_1,\dots,h_n$ (1ドル \le h_i \le n$ for each $i$), the building heights from left to right.
If there are multiple valid solutions, you may output any one of them.
If no valid placement exists, output "no".
5 2 2
yes 1 5 2 3 4
5 3 4
no
10 3 4
yes 4 1 8 5 3 10 6 9 7 2
4 1 4
yes 4 3 2 1
9 1 1
no
6 2 1
yes 5 3 1 2 4 6