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>
#include <cstdio>
#include <cassert>
#include "shoes.h"
#define ll long long
using namespace std;
long long count_swaps(vector<int>massiv)
{
ll n=(ll)massiv.size();
ll cnt=0;
for(ll i=0;i<n-1;i++)
{
if(i>=0 && massiv[i]<0 && massiv[i+1]>0 && -massiv[i]==massiv[i+1])continue;
if(i>0 && massiv[i]>0 && massiv[i-1]<0 && massiv[i]==-massiv[i-1])continue;
ll pos=0;
ll sig=0;
for(ll j=i+1;j<n;j++)
{
if(massiv[i]>0)
{
if(abs(massiv[j])==massiv[i])
{
cnt+=(j-i);
pos=j;
sig=1;
break;
}
}
else
{
if(abs(massiv[i])==massiv[j])
{
cnt+=(j-i-1);
pos=j;
sig=2;
break;
}
}
}
if(sig==1)
{
for(ll j=pos;j>i;j--)swap(massiv[j],massiv[j-1]);
}
else if(sig==2)for(ll j=pos;j>i+1;j--)swap(massiv[j],massiv[j-1]);
}
return cnt;
}
# | 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... |