#include <bits/stdc++.h>
using namespace std;
int n, a[5001], b[5001], l, mp[5001], ta[5001], t, ans=2e9;
int main() {
cin >> n;
for (int i=1; i<=n; i++) cin >> a[i];
for (int mask=0; mask<(1<<n); mask++){
if (__builtin_popcount(mask)%2) continue;
for (int i=1; i<=n; i++) b[i]=i;
l=-1;
for (int i=0; i<n; i++){
if (mask&(1<<i)){
if (l==-1) l=i;
else{
reverse(b+l+1, b+i+2);
l=-1;
}
}
}
for (int i=1; i<=n; i++) mp[b[i]]=i;
for (int i=1; i<=n; i++) ta[i]=mp[a[i]];
t=0;
for (int i=1; i<=n; i++){
for (int j=1; j<i; j++){
if (ta[j]>ta[i]) t++;
}
}
ans=min(ans, t);
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
39 ms |
212 KB |
Output is correct |
12 |
Correct |
79 ms |
304 KB |
Output is correct |
13 |
Correct |
83 ms |
212 KB |
Output is correct |
14 |
Correct |
176 ms |
212 KB |
Output is correct |
15 |
Correct |
165 ms |
212 KB |
Output is correct |
16 |
Correct |
198 ms |
300 KB |
Output is correct |
17 |
Correct |
190 ms |
300 KB |
Output is correct |
18 |
Correct |
166 ms |
304 KB |
Output is correct |
19 |
Correct |
166 ms |
212 KB |
Output is correct |
20 |
Correct |
187 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
39 ms |
212 KB |
Output is correct |
12 |
Correct |
79 ms |
304 KB |
Output is correct |
13 |
Correct |
83 ms |
212 KB |
Output is correct |
14 |
Correct |
176 ms |
212 KB |
Output is correct |
15 |
Correct |
165 ms |
212 KB |
Output is correct |
16 |
Correct |
198 ms |
300 KB |
Output is correct |
17 |
Correct |
190 ms |
300 KB |
Output is correct |
18 |
Correct |
166 ms |
304 KB |
Output is correct |
19 |
Correct |
166 ms |
212 KB |
Output is correct |
20 |
Correct |
187 ms |
300 KB |
Output is correct |
21 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
39 ms |
212 KB |
Output is correct |
12 |
Correct |
79 ms |
304 KB |
Output is correct |
13 |
Correct |
83 ms |
212 KB |
Output is correct |
14 |
Correct |
176 ms |
212 KB |
Output is correct |
15 |
Correct |
165 ms |
212 KB |
Output is correct |
16 |
Correct |
198 ms |
300 KB |
Output is correct |
17 |
Correct |
190 ms |
300 KB |
Output is correct |
18 |
Correct |
166 ms |
304 KB |
Output is correct |
19 |
Correct |
166 ms |
212 KB |
Output is correct |
20 |
Correct |
187 ms |
300 KB |
Output is correct |
21 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
39 ms |
212 KB |
Output is correct |
12 |
Correct |
79 ms |
304 KB |
Output is correct |
13 |
Correct |
83 ms |
212 KB |
Output is correct |
14 |
Correct |
176 ms |
212 KB |
Output is correct |
15 |
Correct |
165 ms |
212 KB |
Output is correct |
16 |
Correct |
198 ms |
300 KB |
Output is correct |
17 |
Correct |
190 ms |
300 KB |
Output is correct |
18 |
Correct |
166 ms |
304 KB |
Output is correct |
19 |
Correct |
166 ms |
212 KB |
Output is correct |
20 |
Correct |
187 ms |
300 KB |
Output is correct |
21 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |