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

17028번 - Sleepy Cow Sorting 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB117158851952.108%

문제

Farmer John is attempting to sort his $N$ cows (1ドル \leq N \leq 100$), conveniently numbered 1ドル \dots N,ドル before they head out to the pastures for breakfast.

Currently, the cows are standing in a line in the order $p_1, p_2, p_3, \dots, p_N,ドル and Farmer John is standing in front of cow $p_1$. He wants to reorder the cows so that they are in the order 1,ドル 2, 3, \dots, N,ドル with cow 1ドル$ next to Farmer John.

The cows are a bit sleepy today, 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 $k$ paces down the line, for any $k$ in the range 1ドル \ldots N-1$. The $k$ cows whom she passes will amble forward, making room for her to insert herself in the line after them.

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

FJ: 4, 3, 2, 1

The only cow paying attention to FJ is cow 4ドル$. If he instructs her to move 2ドル$ 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 3ドル,ドル so in the second time step he may give cow 3ドル$ 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 the minimum number of time steps required to sort the cows.

입력

The first line of input contains $N$.

The second line contains $N$ space-separated integers, $p_1, p_2, p_3, \dots, p_N,ドル indicating the starting order of the cows.

출력

A single integer: the number of time steps before the $N$ cows are in sorted order, if Farmer John acts optimally.

제한

예제 입력 1

4
1 2 4 3

예제 출력 1

3

힌트

출처

Olympiad > USA Computing Olympiad > 2018-2019 Season > USACO 2019 January Contest > Bronze 2번

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

출처

대학교 대회

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

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