結果
| 問題 |
No.2719 Equal Inner Products in Permutation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-05 22:26:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,438 bytes |
| コンパイル時間 | 2,112 ms |
| コンパイル使用メモリ | 199,580 KB |
| 最終ジャッジ日時 | 2025-02-20 21:42:18 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 1 WA * 6 TLE * 1 -- * 22 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << " " << p.second; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#define ASSERT(...) 42
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int oo = 1e9;
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
template<class I> I rnd(I l,I r){return std::uniform_int_distribution<I>(l,r)(rng);}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
vi p(n*3);
iota(all(p),1);
if(n<=6) {
do {
ll ans=0;
for(int i=0;i<n;++i) {
ans+=(ll)p[i]*p[i+n];
}
ll res=0;
for(int i=0;i<n;++i) {
res+=(ll)p[i]*p[i+2*n];
}
if(ans==res) {
cout << p << '\n';
exit(0);
}
} while(next_permutation(all(p)));
cout << "-1\n";
exit(0);
}
int v = n+1;
while(true) {
for(int i=n;i<2*n;++i) {
p[i]=v;
p[i+n]=v+1;
v+=2;
}
const int k= 4;
shuffle(p.begin()+n*2-k,p.begin()+n*2,rng);
shuffle(p.begin()+n*3-k,p.begin()+n*3,rng);
for(int i=0;i<k;++i) {
if(rnd(0,1)) {
swap(p[-i-1+n*3],p[-i-1+n*2]);
}
}
ll ans=0;
for(int i=0;i<n;++i) {
ans+=(ll)p[i]*p[i+n];
}
ll res=0;
for(int i=0;i<n;++i) {
res+=(ll)p[i]*p[i+2*n];
}
ll need = res-ans;
for(int i=2*n-k-1;i>=n;--i) {
ll dif = 2 *(i+1-n);
if(dif<=need) {
need-=dif;
swap(p[i],p[i+n]);
assert(abs(p[i]-p[i+n])==1);
}
}
ans=0;
for(int i=0;i<n;++i) {
ans+=(ll)p[i]*p[i+n];
}
res=0;
for(int i=0;i<n;++i) {
res+=(ll)p[i]*p[i+2*n];
}
debug(need,ans,res);
if(need==0) {
cout << p << '\n';
exit(0);
}
}
}