結果

問題 No.2719 Equal Inner Products in Permutation
ユーザー Jeroen Op de BeekJeroen Op de Beek
提出日時 2024-04-05 23:36:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,523 bytes
コンパイル時間 2,616 ms
コンパイル使用メモリ 209,828 KB
実行使用メモリ 13,480 KB
最終ジャッジ日時 2024-04-05 23:37:04
合計ジャッジ時間 6,429 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);}
void out(vi p) {
    int n = p.size()/3;
    for(int i=0;i<n;++i) swap(p[i],p[i+n]);
    cout << p << '\n';
    exit(0);
}
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) {
                out(p);
            }

        } 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) {
            assert(ans==res);
            out(p);
        }
        
    }
}
0