Submission #315084

# Submission time Handle Problem Language Result Execution time Memory
315084 2020-10-22T02:19:09 Z Seanliu Cat (info1cup19_cat) C++14
0 / 100
343 ms 8440 KB
#include <iostream>
#include <vector>
#include <utility>
#define pii pair<int,int>
#define F first
#define S second
#define ericxiao ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
using namespace std;

const int maxN = 3e6 + 326;

int N, arr[maxN], T;
bool vis[maxN];

inline void makeMove(int i, int j){
	swap(arr[i], arr[j]);
	swap(arr[N - i + 1], arr[N - j + 1]);
}

inline void disp(){
	for(int i = 1; i <= N; i++) cout << arr[i] << " \n"[i == N];
}

inline void solve(){
	cin >> N;
	for(int i = 1; i <= N; i++) cin >> arr[i];
	for(int i = 1; i <= N / 2; i++) if(arr[i] + arr[N - i + 1] != N + 1){
		cout << -1 << endl;
		return;
	}
	vector<int> pos = vector<int>();
	vector<pii> ans = vector<pii>();
	for(int i = 1; i <= N / 2; i++) if(arr[i] > arr[N - i + 1]) pos.push_back(i);
	if(pos.size() & 1){ //not sure about this
		cout << -1 << endl;
		return;
	}
	/*
	cout << "have: ";
	for(int x : pos) cout << x << " ";
	cout << endl;
	*/
	for(int i = 0; i < pos.size(); i += 2){
		makeMove(pos[i], N - pos[i + 1] + 1);	
		ans.emplace_back(pos[i], N - pos[i + 1] + 1);
	}
	disp();
	fill(vis, vis + N + 1, false);
	for(int i = 1; i <= N / 2; i++){
		while(i != arr[i]){
			int nxt = arr[i];
			makeMove(i, arr[i]);
			ans.emplace_back(i, nxt);
			disp();
		}
	}
	cout << ans.size() << " " << ans.size() << endl;
	for(auto [a, b] : ans) cout << a << " " << b << endl;
}

int main(){
	//ericxiao
	cin >> T;
	while(T--){
		solve();
	}
}

Compilation message

cat.cpp: In function 'void solve()':
cat.cpp:44:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for(int i = 0; i < pos.size(); i += 2){
      |                 ~~^~~~~~~~~~~~
cat.cpp:59:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   59 |  for(auto [a, b] : ans) cout << a << " " << b << endl;
      |           ^
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 640 KB Wrong answer
# Verdict Execution time Memory Grader output
1 Incorrect 343 ms 8440 KB Integer parameter [name=x] equals to 19, violates the range [1, 10]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 640 KB Wrong answer
# Verdict Execution time Memory Grader output
1 Incorrect 343 ms 8440 KB Integer parameter [name=x] equals to 19, violates the range [1, 10]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 640 KB Wrong answer