# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153395 | nandonathaniel | Arranging Shoes (IOI19_shoes) | C++14 | 34 ms | 3956 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;
typedef long long LL;
typedef pair<LL,LL> pii;
pii pas[1005];
long long count_swaps(vector<int> s) {
if((LL)s.size()<=2000){
vector<LL> hasil;
LL n=(LL)s.size()/2;
for(LL i=1;i<=n;i++)pas[i]={-1,-1};
for(int i=0;i<s.size();i++){
if(s[i]<0)pas[abs(s[i])].first=i;
else pas[s[i]].second=i;
if(pas[abs(s[i])].first!=-1 && pas[abs(s[i])].second!=-1){
pas[abs(s[i])].first=-1;
pas[abs(s[i])].second=-1;
}
else{
hasil.push_back(-abs(s[i]));
hasil.push_back(abs(s[i]));
}
}
LL res=0;
for(LL i=0;i<s.size();i++){
LL no;
for(LL j=i;j<s.size();j++){
if(s[j]==hasil[i]){
no=j;
break;
}
}
for(LL j=no;j>=i+1;j--){
swap(s[j],s[j-1]);
res++;
}
}
return res;
}
vector<int> v;
for(int i=0;i<s.size();i++){
if(s[i]<0)v.push_back(i);
}
LL now=0,ans=0;
for(int i=0;i<s.size();i++){
if(i%2==0){
ans+=abs(v[now]-i);
now++;
}
}
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... |