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 <cmath>
using namespace std;
long long s;
int val;
long long count_swaps(std::vector<int> shoes) {
s=shoes.size();
if (shoes.size()==2){
return (shoes[0]<0)?0:1;
}
else if (shoes.size()<=2000){
long long ans=0;
for (int x=0;x<s;x+=2){
val=-shoes[x];
for (int y=x+1;;y++){
if (shoes[y]==val){
while (y!=x+1){
swap(shoes[y],shoes[y-1]);
ans++;
y--;
}
break;
}
}
if (shoes[x]>shoes[x+1]) ans++;
}
return ans;
}
else {
s>>=1;
return s*(s-1)/2;
}
}
| # | 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... |