| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 0 | 0 | 0 | 0.000% |
Consider a roll of N paper towels. The roll is unrolled on the floor and its towels are numbered from 1 to N, from left to right. We then perform several folding operations. Specifically, a fold at position p consists of lifting all the towels to the right of the p-th towel and flipping them leftwards. For example, if N = 7, then a fold at position 2 looks like:
| Before | After |
|---|---|
1 2 3 4 5 6 7 |
_ _ _ 4 3 7 6 5 1 2 |
Note that fold positions refer to the towels touching the floor, not necessarily to the numbers on them. For example, if we now perform a fold at position 2 , the result is:
| Before | After |
|---|---|
_ _ _ 4 3 7 6 5 1 2 |
_ 1 _ 2 4 5 3 7 6 |
Folding can also occur at position 0 . In that case we flip over the entire roll.
You are given the initial length of the towel, N, and M folding operations to perform. You must print various details about the final configuration of the paper towels.
The first line contains two integers N and M, representing the length of the roll and the number of operations to perform. Each of the following M lines contains one integer, the position of the fold.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 20 | N, M ≤ 103 |
| 2 | 40 | N, M ≤ 105 |
| 3 | 40 | none |
8 3 6 1 2
7 6 3 2 7 8 1 3 4
The initial layout is
1 2 3 4 5 6 7 8
After the first operation the layout is
_ _ _ _ 8 7 1 2 3 4 5 6
After the second operation the layout is
6 5 _ _ 2 7 8 4 3 1
After the third operation the layout is
_ 3 4 1 6 5 2 7 8