302357: CF454B. Little Pony and Sort by Shift
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Little Pony and Sort by Shift
题意翻译
题目描述: 一天,暮光闪闪对如何给一个整数数组按照不递减顺序排序产生了兴趣。作为一只年轻的独角兽,她能做的只有一个操作:单位移动。她可以把最后一个元素移动到第一个去:$a_1,a_2,\cdots ,a_n\to a_n,a_1,a_2,\cdots ,a_{n-1}$ 帮助暮光闪闪确定:最少需要花多少次操作才能把数组排好序? 输入格式: 第一行一个正整数 n$(2\le n\le 10^5)$,表示数组大小。 第二行 n个正整数 $a_1,a_2,\cdots,a_n (1\le a_i\le 10^5)$,表示数组中的元素。 输出格式: 如果不可能完成,输出-1,否则输出最少花费的操作数。 Translated by 小粉兔题目描述
One day, Twilight Sparkle is interested in how to sort a sequence of integers $ a_{1},a_{2},...,a_{n} $ in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: $ a_{1},a_{2},...,a_{n}→a_{n},a_{1},a_{2},...,a_{n-1}. $ Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?输入输出格式
输入格式
The first line contains an integer $ n $ $ (2<=n<=10^{5}) $ . The second line contains $ n $ integer numbers $ a_{1},a_{2},...,a_{n} $ $ (1<=a_{i}<=10^{5}) $ .
输出格式
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
输入输出样例
输入样例 #1
2
2 1
输出样例 #1
1
输入样例 #2
3
1 3 2
输出样例 #2
-1
输入样例 #3
2
1 2
输出样例 #3
0