結果
| 問題 |
No.2719 Equal Inner Products in Permutation
|
| コンテスト | |
| ユーザー |
遭難者
|
| 提出日時 | 2024-04-07 18:19:17 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 46 ms / 2,000 ms |
| コード長 | 2,659 bytes |
| コンパイル時間 | 7,301 ms |
| コンパイル使用メモリ | 346,504 KB |
| 実行使用メモリ | 19,044 KB |
| 最終ジャッジ日時 | 2024-10-01 04:38:02 |
| 合計ジャッジ時間 | 10,626 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
#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;
}
遭難者