제출 #906247

#제출 시각아이디문제언어결과실행 시간메모리
906247vjudge1Arranging Shoes (IOI19_shoes)C++17
45 / 100
61 ms9500 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define F(i, l, r) for (ll i = l; i < (r); ++i)
using vl = vector<ll>;
#define A(a) (a).begin(), (a).end()

long long count_swaps(std::vector<int> s) {
    ll n = s.size()/2;
    map<ll, ll> cnt;
    for (auto x: s) cnt[abs(x)]++;

	if (n <= 8) {
        vl perm; for (auto [k, v]: cnt) {
            v/=2;
            while(v-- ) perm.push_back(k);
        }
        sort(A(perm));
        ll ans = 1e9;
        do {
            vl ts(A(s));
            ll tans = 0;
            for (auto v: perm) {
                auto x = find(A(ts), -v);
                tans += x - ts.begin();
                ts.erase(x);
                x = find(A(ts), v);
                tans += x - ts.begin();
                ts.erase(x);
            }
            ans = min(ans, tans);

        } while (next_permutation(A(perm)));
        return ans;
    }
    if (cnt.size() == 1) {
        // subtask 3; thinking 
    }
    bool subtask4 = 1;
    F(i, 0, n) {
        subtask4 &= abs(s[i]) == abs(s[i + n]);
        subtask4 &= s[i] < 0;
        subtask4 &= s[i + n] > 0;
    }
    if (subtask4) return n * (n-1)/2;

    return -1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...