# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
783093 |
2023-07-14T15:21:05 Z |
Andrey |
Cat (info1cup19_cat) |
C++14 |
|
189 ms |
1548 KB |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n,a,br = 0,y,b;
cin >> n;
vector<int> p(n+1);
for(int i = 1; i <= n; i++) {
cin >> a;
p[a] = i;
}
for(int i = 1; i <= n/2; i++) {
if(p[i] > p[n-i+1]) {
br++;
}
if(p[i] != n-p[n-i+1]+1) {
cout << -1 << "\n";
return;
}
}
if(br%2) {
cout << -1 << "\n";
return;
}
br = 0;
for(int i = 1; i <= n; i++) {
y = i;
while(p[y] != y && p[y] != n-y+1) {
a = y;
b = p[y];
swap(p[a],p[b]);
swap(p[n-a+1],p[n-b+1]);
br++;
}
}
for(int i = 1; i <= n/2; i++) {
if(p[i] == n-i+1) {
br++;
}
}
cout << br << " " << 0 << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while(t--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Correct number of moves |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
340 KB |
Correct number of moves |
2 |
Correct |
9 ms |
340 KB |
Correct number of moves |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Correct number of moves |
2 |
Correct |
9 ms |
340 KB |
Correct number of moves |
3 |
Correct |
9 ms |
340 KB |
Correct number of moves |
4 |
Correct |
12 ms |
340 KB |
Correct number of moves |
5 |
Correct |
4 ms |
328 KB |
Correct number of moves |
6 |
Correct |
5 ms |
340 KB |
Correct number of moves |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
340 KB |
Correct number of moves |
2 |
Correct |
9 ms |
340 KB |
Correct number of moves |
3 |
Correct |
166 ms |
688 KB |
Correct number of moves |
4 |
Correct |
172 ms |
788 KB |
Correct number of moves |
5 |
Correct |
170 ms |
992 KB |
Correct number of moves |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Correct number of moves |
2 |
Correct |
9 ms |
340 KB |
Correct number of moves |
3 |
Correct |
9 ms |
340 KB |
Correct number of moves |
4 |
Correct |
12 ms |
340 KB |
Correct number of moves |
5 |
Correct |
4 ms |
328 KB |
Correct number of moves |
6 |
Correct |
5 ms |
340 KB |
Correct number of moves |
7 |
Correct |
166 ms |
688 KB |
Correct number of moves |
8 |
Correct |
172 ms |
788 KB |
Correct number of moves |
9 |
Correct |
170 ms |
992 KB |
Correct number of moves |
10 |
Correct |
167 ms |
480 KB |
Correct number of moves |
11 |
Correct |
172 ms |
560 KB |
Correct number of moves |
12 |
Correct |
178 ms |
1096 KB |
Correct number of moves |
13 |
Correct |
189 ms |
1548 KB |
Correct number of moves |
14 |
Correct |
183 ms |
1060 KB |
Correct number of moves |