Submission #944795

#TimeUsernameProblemLanguageResultExecution timeMemory
944795PenguinsAreCuteArranging Shoes (IOI19_shoes)C++17
10 / 100
1088 ms4308 KiB
#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 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...