Submission #522290

# Submission time Handle Problem Language Result Execution time Memory
522290 2022-02-04T13:55:44 Z amunduzbaev Cat (info1cup19_cat) C++17
0 / 100
18 ms 460 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array
typedef long long ll;

void solve(){
	int n; cin>>n;
	vector<int> a(n), pos(n);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) pos[--a[i]] = i;
	vector<ar<int, 2>> res;
	
	auto add = [&](int i, int j){
		int i_ = n - i - 1, j_ = n - j - 1;
		assert(j != i_);
		swap(a[i], a[j]);
		swap(pos[a[i]], pos[a[j]]);
		res.push_back({i, j});
		swap(a[i_], a[j_]);
		swap(pos[a[i_]], pos[a[j_]]);
	};
	//~ int cnt = 0;
	
	for(int i=0;i<n/2;i++){
		if(a[i] == i) continue;
		int j = pos[i];
		if(j < n/2){
			add(i, j);
		} else {
			if(n - j - 1 < i){
				cout<<-1<<"\n";
				return;
			}
			
			if(n - j - 1 == i){
				add(i, i + 1);
				add(i, pos[i]);
			} else {
				add(i, j);
			}
		}
		if(a[n - i - 1] != n - i - 1){
			cout<<-1<<"\n";
			return;
		}
	}
	
	cout<<(int)res.size()<<" "<<(int)res.size()<<"\n";
	for(auto x : res) cout<<x[0] + 1<<" "<<x[1] + 1<<"\n";
}

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int t; cin>>t;
	while(t--){
		solve();
	}
}

/*

10
4 9 6 3 1 ' 10 8 5 2 7
1 9 6 3 4 ' 7 8 5 2 10
1 2 3 4 5 ' 6 7 8 9 10

6
2 6 4 ' 3 1 5
1 2 3 ' 4 5 6

*/
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 460 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 460 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -