← Real problems

dmopc21c5p2

easyconstructiveStatement on DMOJ

CP Lang

6 lineschecks
// dmopc21c5p2: construct the permutation; 1 3 2 4 5 ... n works for every n except 2.
let n = read<1..=1_000_000>()
if n == 2:
    print(-1)
else:
    print(chain([1, 3, 2], 4..=n).take(n))

Accepted C++

62 lines · 1.56 s on the judge
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
	cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
	cerr << t << " | ";
	dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
	cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
		 << ": ";                                          \
	dbgh(__VA_ARGS__)
#else
#define cerr   \
	if (false) \
	cerr
#define dbg(...) 1412
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())

void solve() {
	int n;
	cin >> n;
	if (n == 2) {
		cout << -1 << endl;
	} else {
		vector<int> arr;
		arr.push_back(1);
		arr.push_back(3);
		arr.push_back(2);
		for (int i = 4; i <= n; i++) {
			arr.push_back(i);
		}
		for (int i = 0; i < n; i++) {
			cout << arr[i] << " \n"[i == n - 1];
		}
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cin.exceptions(ios::failbit);
	int t = 1;
	// cin >> t;
	for (int _ = 1; _ <= t; _++) {
		dbg(_);
		// cout << "Case #" << _ << ": ";
		solve();
	}
}