結果

問題 No.2719 Equal Inner Products in Permutation
ユーザー 遭難者遭難者
提出日時 2024-04-07 18:19:17
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 2,659 bytes
コンパイル時間 7,355 ms
コンパイル使用メモリ 346,828 KB
実行使用メモリ 19,036 KB
最終ジャッジ日時 2024-04-07 18:19:29
合計ジャッジ時間 12,276 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 39 ms
16,540 KB
testcase_16 AC 46 ms
18,184 KB
testcase_17 AC 29 ms
12,544 KB
testcase_18 AC 47 ms
18,376 KB
testcase_19 AC 39 ms
15,720 KB
testcase_20 AC 26 ms
11,756 KB
testcase_21 AC 45 ms
18,532 KB
testcase_22 AC 34 ms
14,120 KB
testcase_23 AC 31 ms
13,272 KB
testcase_24 AC 27 ms
11,488 KB
testcase_25 AC 47 ms
19,036 KB
testcase_26 AC 47 ms
19,036 KB
testcase_27 AC 47 ms
19,004 KB
testcase_28 AC 47 ms
19,036 KB
testcase_29 AC 47 ms
19,036 KB
testcase_30 AC 47 ms
19,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#else
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast,unroll-loops")
#endif
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using mint = atcoder::modint1000000007;
istream& operator>>(istream& is, mint& a) {
	int t; is >> t; a = t;
	return is;
}
ostream& operator<<(ostream& os, mint a) {
	return os << a.val();
}
#endif
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(a) a.begin(), a.end()
#define vec vector
#undef long
#define long long long
template<typename T>
ostream& operator<<(ostream& os, vector<T> a) {
	const int n = a.size();
	rep(i, n) os << a[i] << " \n"[i + 1 == n];
	return os;
}
template<typename T, size_t n>
ostream& operator<<(ostream& os, array<T, n> a) {
	rep(i, n) os << a[i] << " \n"[i + 1 == n];
	return os;
}
template<typename T>
istream& operator>>(istream& is, vector<T>& a) {
	for (T& i : a) is >> i;
	return is;
}
template<typename T>
bool chmin(T& x, T y) {
	if (x > y) { x = y; return true; }
	return false;
}
template<typename T>
bool chmax(T& x, T y) {
	if (x < y) { x = y; return true; }
	return false;
}
template<typename T>
void operator++(vector<T>& a) {
	for (T& i : a) ++i;
}
template<typename T>
void operator--(vector<T>& a) {
	for (T& i : a) --i;
}
template<typename T>
void operator++(vector<T>& a, int) {
	for (T& i : a) i++;
}
template<typename T>
void operator--(vector<T>& a, int) {
	for (T& i : a) i--;
}
#undef endl
#define endl '\n'
void solve() {
	int n; cin >> n;
	if (n == 1) {
		cout << -1 << endl;
		return;
	}
	if (n == 2) {
		cout << "1 4 3 6 5 2" << endl;
		return;
	}
	const int nn = 3 * n;
	vec<long> a(n), b(n), c(n);
	iota(ALL(a), 1);
	int now = n;
	rep(i, n) {
		b[i] = ++now;
		c[i] = ++now;
	}
	if ((n * (long)(n + 1) / 2) & 1) swap(a[n - 1], b[0]);
	per(sk, n) {
		vec<long> aa(n);
		aa[0] = a[sk];
		int idx = 0;
		per(i, n) {
			if (i == sk) continue;
			aa[++idx] = a[i];
		}
		vec<bool> fu(n);
		long now = 0;
		rep(i, n) {
			if (now >= 0) {
				now += aa[i] * (b[i] - c[i]);
				fu[i] = true;
			}
			else {
				now -= aa[i] * (b[i] - c[i]);
				fu[i] = false;
			}
		}
		if (now != 0) continue;
		vec<long> ans(nn);
		rep(i, n) {
			ans[n + i] = aa[i];
			ans[i] = b[i];
			ans[2 * n + i] = c[i];
			if (fu[i]) swap(ans[i], ans[2 * n + i]);
		}
		long jud = 0;
		rep(i, n) jud += ans[n + i] * (ans[i] - ans[2 * n + i]);
		assert(jud == 0);
		cout << ans;
		return;
	}
}
int main() {
	// srand((unsigned)time(NULL));
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	// cout << fixed << setprecision(40);
	solve();
	return 0;
}
0