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 ft {
vector<int> v; int n;
ft(int _n): n(_n) {v.resize(n+1,0);}
~ft() {v.clear();}
inline int lsb(int x) {return x&(-x);}
void up(int x, int u) {
for(;x<=n;x+=lsb(x)) v[x]+=u;
}
int qry(int x) {
ll ans = 0;
for(;x;x-=lsb(x)) ans += v[x];
return ans;
}
};
long long count_swaps(std::vector<int> s) {
int n = s.size() / 2;
ll ans = 696969;
vector<int> t; for(int i=0;i<2*n;i++) t.push_back(i);
do {
bool ok = 1;
for(int i=0;i<2*n;i+=2) if((s[t[i]]+s[t[i+1]])||s[t[i]]>0) ok = 0;
if(!ok) continue;
ll cur = 0;
ft fenwick(2*n);
for(int i=2*n;i--;) {
cur += fenwick.qry(t[i]);
fenwick.up(t[i]+1,1);
}
ans = min(ans, cur);
} while(next_permutation(t.begin(),t.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... |