Submission #519126

#TimeUsernameProblemLanguageResultExecution timeMemory
519126lucriCat (info1cup19_cat)C++17
100 / 100
931 ms12372 KiB
#include <iostream> using namespace std; int ans1[6000010],v[3000010],r,n,ans2[6000010],ans,poz[3000010]; int main() { int t; cin>>t; ++t; while(--t) { int ver=0; cin>>n; for(int i=1;i<=n;++i) { cin>>v[i]; poz[v[i]]=i; } n/=2; for(int i=1;i<=n;++i) { if(v[i]+v[2*n+1-i]!=2*n+1) { ver=1; break; } if(v[i]>n) ++ver; } if(ver%2==1) { cout<<-1<<'\n'; continue; } ans=0; ver=0; for(int i=1;i<=n;++i) { while(v[i]!=i&&v[i]!=n*2-i+1) { ++ans; ans1[ans]=v[i]; ans2[ans]=i; swap(poz[v[i]],poz[v[v[i]]]); swap(poz[v[2*n-i+1]],poz[v[2*n-v[i]+1]]); swap(v[2*n-i+1],v[2*n-v[i]+1]); swap(v[i],v[v[i]]); } } for(int i=1;i<=n;++i) { if(v[i]>n) { if(ver==0) ver=i; else { ++ans; ans1[ans]=ver; ans2[ans]=2*n-i+1; swap(v[i],v[2*n-ver+1]); swap(v[ver],v[2*n-i+1]); swap(poz[v[i]],poz[v[2*n-ver+1]]); swap(poz[v[ver]],poz[v[2*n-i+1]]); ++ans; ans1[ans]=ver; ans2[ans]=i; swap(v[i],v[ver]); swap(v[2*n-ver+1],v[2*n-i+1]); swap(poz[v[i]],poz[v[ver]]); swap(poz[v[2*n-ver+1]],poz[v[2*n-i+1]]); ver=0; } } } cout<<ans<<' '<<ans<<'\n'; for(int i=1;i<=ans;++i) cout<<ans1[i]<<' '<<ans2[i]<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...