結果

問題 No.2719 Equal Inner Products in Permutation
ユーザー Jeroen Op de BeekJeroen Op de Beek
提出日時 2024-04-05 22:21:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,216 bytes
コンパイル時間 2,185 ms
コンパイル使用メモリ 208,812 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-05 22:22:06
合計ジャッジ時間 10,930 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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);}
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;
    for(int i=n;i<2*n;++i) {
        p[i]=v;
        p[i+n]=v+1;
        v+=2;
    }
    while(true) {
    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-4;i>=n;--i) {
        ll dif = 2 *(i+1-n);
        if(dif<=need) {
            need-=dif;

            swap(p[i],p[i+n]);
        }
    }
    debug(need);
        if(need==0) {
            cout << p << '\n';
            exit(0);
        }
        
    }
}
0