# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
861280 | Ahmed57 | Cat (info1cup19_cat) | C++17 | 449 ms | 23752 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> con;
bool vis[200001];int arr[200001];
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int t;cin>>t;
z:while(t--){
int n;cin>>n;
for(int i = 1;i<=n;i++)vis[i] = 0;
con.clear();
int pos[n+1];
for(int i = 1;i<=n;i++){
cin>>arr[i];pos[arr[i]] = i;
}
int g = 0;int lol = 0;
for(int i = 1;i<=n/2;i++){
if(arr[i]!=i)g++;
if(n-arr[i]+1!=arr[n-i+1]){
cout<<-1<<endl;
goto z;
}if(arr[i]>n/2){
lol++;
}
}
if(lol&1){
cout<<-1<<endl;
goto z;
}
for(int i = 1;i<=n;i++){
if(!vis[i]&&arr[i]<=n/2){
int st = i;
vis[i] = 1;
int e = arr[i];
while(vis[e]==0){
vis[e] = 1;
con.push_back({e,i});
e = arr[e];
}
}
}
cout<<con.size()<<" "<<con.size()<<"\n";
for(auto i:con)cout<<i.first<<" "<<i.second<<"\n";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |