# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
751351 | kusmetliq | Arranging Shoes (IOI19_shoes) | C++14 | 373 ms | 3132 KiB |
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;
long long count_swaps(vector<int> a) {
if(a.size()<=2000) {
int n=a.size()/2;
long long ans=0;
while(a.size()>0) {
map<int,int>m;
for(int i=0; i<a.size(); i++) {
if(m[a[i]]==0)m[a[i]]=i+1;
}
int minscore=2*n;
int scoreval=0;
for(int i=1; i<=n+69; i++) {
if(m[i]==0)continue;
int updscore=0;
updscore+=m[i]-1;
updscore+=m[-i]-1;
if(m[-i]<m[i])updscore--;
if(updscore<minscore) {
minscore=updscore;
scoreval=i;
}
}
ans+=minscore;
a.erase(find(a.begin(),a.end(),scoreval));
a.erase(find(a.begin(),a.end(),-scoreval));
}
return ans;
} else {
int n=a.size();
int curcnt=0;
long long ans=0;
for(int i=0; i<a.size(); i++) {
if(a[i]<0) {
ans+=abs(i-(curcnt*2));
curcnt++;
}
}
return ans;
}
}
Compilation message (stderr)
# | 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... |