#include <bits/stdc++.h>
using namespace std;
const int nmax = 2e5;
int n;
int v[nmax + 5];
int poz[nmax + 5];
set<int,greater<int>> s;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>v[i];
s.insert(i);
}
for(int i=n;i>=1;i--)
{
auto it = s.lower_bound(v[i]);
if(it==s.end())
{
cout<<-1<<'\n';
return 0;
}
poz[i] = *it;
s.erase(it);
}
int rez = 0;
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(poz[i] > poz[j])
{
++rez;
}
}
}
cout<<rez<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
596 KB |
Output is correct |
2 |
Correct |
11 ms |
640 KB |
Output is correct |
3 |
Correct |
9 ms |
636 KB |
Output is correct |
4 |
Correct |
9 ms |
596 KB |
Output is correct |
5 |
Correct |
9 ms |
596 KB |
Output is correct |
6 |
Correct |
9 ms |
592 KB |
Output is correct |
7 |
Correct |
9 ms |
628 KB |
Output is correct |
8 |
Correct |
9 ms |
628 KB |
Output is correct |
9 |
Correct |
9 ms |
596 KB |
Output is correct |
10 |
Correct |
9 ms |
596 KB |
Output is correct |
11 |
Correct |
11 ms |
632 KB |
Output is correct |
12 |
Correct |
9 ms |
596 KB |
Output is correct |
13 |
Correct |
9 ms |
596 KB |
Output is correct |
14 |
Correct |
9 ms |
596 KB |
Output is correct |
15 |
Correct |
9 ms |
596 KB |
Output is correct |
16 |
Correct |
9 ms |
632 KB |
Output is correct |
17 |
Correct |
9 ms |
596 KB |
Output is correct |
18 |
Correct |
9 ms |
592 KB |
Output is correct |
19 |
Correct |
10 ms |
596 KB |
Output is correct |
20 |
Correct |
9 ms |
596 KB |
Output is correct |
21 |
Correct |
10 ms |
596 KB |
Output is correct |
22 |
Correct |
10 ms |
592 KB |
Output is correct |
23 |
Correct |
10 ms |
596 KB |
Output is correct |
24 |
Correct |
9 ms |
628 KB |
Output is correct |
25 |
Correct |
9 ms |
596 KB |
Output is correct |
26 |
Correct |
9 ms |
596 KB |
Output is correct |
27 |
Correct |
10 ms |
596 KB |
Output is correct |
28 |
Correct |
9 ms |
600 KB |
Output is correct |
29 |
Correct |
9 ms |
640 KB |
Output is correct |
30 |
Correct |
9 ms |
632 KB |
Output is correct |
31 |
Correct |
2 ms |
596 KB |
Output is correct |
32 |
Correct |
9 ms |
596 KB |
Output is correct |
33 |
Correct |
9 ms |
636 KB |
Output is correct |
34 |
Correct |
9 ms |
624 KB |
Output is correct |
35 |
Correct |
2 ms |
596 KB |
Output is correct |
36 |
Correct |
9 ms |
568 KB |
Output is correct |
37 |
Correct |
9 ms |
596 KB |
Output is correct |
38 |
Correct |
9 ms |
632 KB |
Output is correct |
39 |
Correct |
9 ms |
596 KB |
Output is correct |
40 |
Correct |
9 ms |
576 KB |
Output is correct |
41 |
Correct |
2 ms |
596 KB |
Output is correct |
42 |
Correct |
9 ms |
632 KB |
Output is correct |
43 |
Correct |
2 ms |
596 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
596 KB |
Output is correct |
2 |
Correct |
11 ms |
640 KB |
Output is correct |
3 |
Correct |
9 ms |
636 KB |
Output is correct |
4 |
Correct |
9 ms |
596 KB |
Output is correct |
5 |
Correct |
9 ms |
596 KB |
Output is correct |
6 |
Correct |
9 ms |
592 KB |
Output is correct |
7 |
Correct |
9 ms |
628 KB |
Output is correct |
8 |
Correct |
9 ms |
628 KB |
Output is correct |
9 |
Correct |
9 ms |
596 KB |
Output is correct |
10 |
Correct |
9 ms |
596 KB |
Output is correct |
11 |
Correct |
11 ms |
632 KB |
Output is correct |
12 |
Correct |
9 ms |
596 KB |
Output is correct |
13 |
Correct |
9 ms |
596 KB |
Output is correct |
14 |
Correct |
9 ms |
596 KB |
Output is correct |
15 |
Correct |
9 ms |
596 KB |
Output is correct |
16 |
Correct |
9 ms |
632 KB |
Output is correct |
17 |
Correct |
9 ms |
596 KB |
Output is correct |
18 |
Correct |
9 ms |
592 KB |
Output is correct |
19 |
Correct |
10 ms |
596 KB |
Output is correct |
20 |
Correct |
9 ms |
596 KB |
Output is correct |
21 |
Correct |
10 ms |
596 KB |
Output is correct |
22 |
Correct |
10 ms |
592 KB |
Output is correct |
23 |
Correct |
10 ms |
596 KB |
Output is correct |
24 |
Correct |
9 ms |
628 KB |
Output is correct |
25 |
Correct |
9 ms |
596 KB |
Output is correct |
26 |
Correct |
9 ms |
596 KB |
Output is correct |
27 |
Correct |
10 ms |
596 KB |
Output is correct |
28 |
Correct |
9 ms |
600 KB |
Output is correct |
29 |
Correct |
9 ms |
640 KB |
Output is correct |
30 |
Correct |
9 ms |
632 KB |
Output is correct |
31 |
Correct |
2 ms |
596 KB |
Output is correct |
32 |
Correct |
9 ms |
596 KB |
Output is correct |
33 |
Correct |
9 ms |
636 KB |
Output is correct |
34 |
Correct |
9 ms |
624 KB |
Output is correct |
35 |
Correct |
2 ms |
596 KB |
Output is correct |
36 |
Correct |
9 ms |
568 KB |
Output is correct |
37 |
Correct |
9 ms |
596 KB |
Output is correct |
38 |
Correct |
9 ms |
632 KB |
Output is correct |
39 |
Correct |
9 ms |
596 KB |
Output is correct |
40 |
Correct |
9 ms |
576 KB |
Output is correct |
41 |
Correct |
2 ms |
596 KB |
Output is correct |
42 |
Correct |
9 ms |
632 KB |
Output is correct |
43 |
Correct |
2 ms |
596 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
328 KB |
Output is correct |
46 |
Execution timed out |
1073 ms |
12572 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |