This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "shoes.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct BIT{
ll n;
vector<ll> a;
BIT(ll N):n(N),a(N+1,0){}
void add(ll i, ll v){
for(;i<=n;i+=i&-i) a[i] += v;
}
ll get(ll i){
ll x = 0;
for(;i>0;i-=i&-i) x += a[i];
return x;
}
};
ll invc(const vector<ll>& v){
ll n = v.size();
BIT t(n);
ll r = 0;
for(ll i = 0;i<n;i++){
r += i-t.get(v[i]+1);
t.add(v[i]+1,1);
}
return r;
}
long long count_swaps(std::vector<int> s) {
ll n = s.size()/2;
ll ans = n*n*10;
vector<ll> p(n*2);
iota(p.begin(),p.end(),0);
do{
ll ok = 1;
for(ll i = 0;i<n;i++){
if (s[p[i*2]]>0||s[p[i*2+1]]<0||s[p[i*2]]+s[p[i*2+1]]!=0) {
ok = 0;
break;
}
}
if(ok){
ans = min(ans,invc(p));
}
}while(next_permutation(p.begin(),p.end()));
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |