제출 #475022

#제출 시각아이디문제언어결과실행 시간메모리
475022hhhhauraCat (info1cup19_cat)C++14
40 / 100
590 ms15904 KiB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
using namespace std;
#define pii pair<int, int>
namespace solver {
	int n;
	vector<int> a, b, vis;
	vector<pii> ans;
	void init_(int _n) {
		n = _n;
		a.assign(n + 1, 0);
		b.assign(n + 1, 0);
		ans.clear();
	}
	void sswap(int x, int y) {
		ans.push_back({x, y});
		swap(a[x], a[y]);
		swap(a[n - x + 1], a[n - y + 1]);
	}
	int get(int x) {
		return x > n / 2 ? n - x + 1: x;
	}
	void solve() {
		int cnt = 0;
		rep(i, 1, n / 2) {
			if(a[i] + a[n - i + 1] != n + 1) {
				cout << "-1\n";
				return;
			}
			if(a[i] > n / 2) cnt ++;
		}
		if(cnt & 1) {
			cout << "-1\n";
			return;
		}
		vector<int> temp;
		vis.assign(n + 1, 0);
		int pre = 0;
		rep(i, 1, n / 2) if(!vis[i]) {
			temp.clear(), vis[i] = 1;
			if(a[i] > n / 2) temp.push_back(i);
			for(int j = get(a[i]); j != i; j = get(a[j])) {
				if(a[j] > n / 2) temp.push_back(j);
				vis[j] = 1;
			}
			if(temp.size() % 2 == 1) {
				if(pre) sswap(pre, n - temp.back() + 1), pre = 0;
				else pre = temp.back();
				temp.pop_back();
			}
			for(int j = 0; j < temp.size(); j += 2) 
				sswap(temp[j], n - temp[j + 1] + 1);
		}
		vis.assign(n + 1, 0);
		rep(i, 1, n / 2) if(!vis[i]) {
			temp.clear(), vis[i] = 1;
			temp.push_back(i);
			for(int j = get(a[i]); j != i; j = get(a[j])) {
				temp.push_back(j), vis[j] = 1;
			}
			for(int j = 1; j < temp.size(); j ++) 
				sswap(temp[j], temp[j - 1]);
		}
		cout << ans.size() << " " << ans.size() << "\n";
		for(auto i : ans) cout << i.first << " " << i.second << "\n";
	}
};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int t; cin >> t;
	while(t--) {
		int n; cin >> n;
		init_(n);
		rep(i, 1, n) cin >> a[i];
		solve();
	}
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

cat.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
cat.cpp: In function 'void solver::solve()':
cat.cpp:56:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |    for(int j = 0; j < temp.size(); j += 2)
      |                   ~~^~~~~~~~~~~~~
cat.cpp:66:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |    for(int j = 1; j < temp.size(); j ++)
      |                   ~~^~~~~~~~~~~~~
#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...