# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
719166 | AndrijaM | Arranging Shoes (IOI19_shoes) | C++14 | 22 ms | 3792 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 <bits/stdc++.h>
using ll=long long;
using namespace std;
ll count_swaps(vector<int> a) {
ll n = a.size();
ll ans = 0;
if(n<=1010)
{
bool vis[n];
memset(vis,0,sizeof vis);
for(ll i=0;i<n;i++)
{
if(vis[i])continue;
ll j=i+1;
ll val=0;
while(a[j]!=-a[i] || vis[j])
{
if(!vis[j])val++;
j++;
}
if(a[i]>0)
{
ans+=val+1;
}
else
{
ans+=val;
}
vis[i]=vis[j]=true;
}
}
else
{
vector<int>v;
for(ll idx=0;idx<n;idx++)
{
if(a[idx]<0)
v.push_back(idx);
}
sort(v.begin(),v.end());
ll k=0;
for(ll idx=0;idx<v.size();idx++)
{
ans+=abs(v[idx]-k);
k+=2;
}
}
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... |