#413
Unrated
Sleepy Cow Sorting
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Farmer John is attempting to sort his NN cows (1N1051 \leq N \leq 10^5), conveniently numbered 1N1 \dots N, before they head out to the pastures for breakfast.

Currently, the cows are standing in a line in the order p1,p2,p3,,pNp_1, p_2, p_3, \dots, p_N, and Farmer John is standing in front of cow p1p_1. He wants to reorder the cows so that they are in the order 1,2,3,,N1, 2, 3, \dots, N, with cow 11 next to Farmer John.

Today the cows are a bit sleepy, so at any point in time the only cow who is paying attention to Farmer John's instructions is the cow directly facing Farmer John. In one time step, he can instruct this cow to move kk paces down the line, for any kk between 11 and N1N-1 inclusive. The kk cows whom she passes will amble forward, making room for her to insert herself in the line after them.

For example, suppose that N=4N=4 and the cows start off in the following order:

FJ: 4, 3, 2, 1

The only cow paying attention to FJ is cow 44. If he instructs her to move 22 paces down the line, the order will subsequently look like this:

FJ: 3, 2, 4, 1

Now the only cow paying attention to FJ is cow 33, so in the second time step he may give cow 33 an instruction, and so forth until the cows are sorted.

Farmer John is eager to complete the sorting, so he can go back to the farmhouse for his own breakfast. Help him find a sequence of instructions that sorts the cows in the minimum number of time steps.

입력

The first line of input contains NN. The second line contains NN space-separated integers: p1,p2,p3,,pNp_1, p_2, p_3, \dots, p_N, indicating the starting order of the cows.

출력

The first line should contain a single integer, KK, giving the minimum number of time steps required to sort the cows.

The second line should contain KK space-separated integers, c1,c2,,cKc_1, c_2, \dots, c_K, each in the range 1N11 \ldots N-1.
Furthermore, if in the ii-th time step FJ instructs the cow facing him to move cic_i paces down the line, then after KK time steps the cows should be in sorted order.

If there are multiple optimal instruction sequences, your program may output any of them.

예제 입력 1

4
1 2 4 3

예제 출력 1

3
2 2 3
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.