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>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define F first
#define S second
#define INF 10000000
#define inf -10000000
#define pb push_back
#define forr(i,p,n) for(int i=p;i<n;i++)
#define mp make_pair
#define upb(a,s) upper_bound(a.begin(),a.end(),s)
#define lwb(a,s) lower_bound(a.begin(),a.end(),s)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
long long count_swaps(std::vector<int> s) {
if(s.size()==2){
if(s[0]<s[1])return 0;
else return 1;
}else{
ll c=0;
for(int i=0;i<s.size();i+=2){
if(s[i]<0){
int h=s[i]*-1;
int k=0;
for(int j=i+1;j<s.size();j++){
if(h==s[j]){
k=j;
c+=abs(i+1-j);
break;
}
}
for(int j=k;j>i+1;j--){
swap(s[j],s[j-1]);
}
}
else{
int h=s[i]*-1;
int k=0;
for(int j=i+1;j<s.size();j++){
if(h==s[j]){
k=j;
c+=abs(i-j);
break;
}
}
for(int j=k;j>i;j--){
swap(s[j],s[j-1]);
}
}
/*cout<<c<<endl;
for(int i=0;i<s.size();i++){
cout<<s[i]<<" ";
}
cout<<endl;*/
}
return c;
}
}
Compilation message (stderr)
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:27:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<s.size();i+=2){
~^~~~~~~~~
shoes.cpp:31:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=i+1;j<s.size();j++){
~^~~~~~~~~
shoes.cpp:45:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=i+1;j<s.size();j++){
~^~~~~~~~~
# | 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... |