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 vi vector<int>
#define ll long long
using namespace std;
ll count_swaps(vector<int> s){
int n = s.size() / 2;
ll ans = 0;
int l,r;
for(int i = 0 ; i < 2*n ; i++){
if(s[i]<0){
l=i;
break;
}
}
for(int i = 0 ;i < 2*n ; i++){
if(s[i]>0){
r=i;
break;
}
}
for(int i = 0 ; i < 2* n ; i++){
if(s[i] < 0){
ans += r-l-1;
}
else{
ans += l-r;
}
for(int j = l+1 ; j < s.size();j++){
if(s[j]<0){
l=j;
break;
}
}
for(int j = r+1 ; j < s.size();j++){
if(s[j]>0){
r=j;
break;
}
}
s.erase(s.begin() + max(l,r));
}
return ans;
}
// int main(){
// int p=1,n=-1;
// cout << count_swaps({p,n,n,n,n,p,p,n,p,p,p,n,n,p}) << endl;
// }
Compilation message (stderr)
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int j = l+1 ; j < s.size();j++){
| ~~^~~~~~~~~~
shoes.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int j = r+1 ; j < s.size();j++){
| ~~^~~~~~~~~~
shoes.cpp:31:12: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
31 | ans += l-r;
| ~^~
shoes.cpp:31:12: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | 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... |