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 < s.size() ; i++){
if(s[i] < 0){
ans += r-l-1;
s.erase(s.begin()+r);
for(int j = l+1 ; j < s.size() ; j++){
if(s[j] <0){
l=j;
break;
}
}
for(int j = r ; j < s.size() ; j++){
if(s[j]>0){
r=j;
break;
}
}
}
else{
ans += l-r;
s.erase(s.begin() + l);
for(int j = r+1 ; j < s.size() ; j++){
if(s[j] >0){
r=j;
break;
}
}
for(int j = l ; j < s.size() ; j++){
if(s[j]<0){
l=j;
break;
}
}
}
}
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:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 0 ; i < s.size() ; i++){
| ~~^~~~~~~~~~
shoes.cpp:29:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int j = l+1 ; j < s.size() ; j++){
| ~~^~~~~~~~~~
shoes.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int j = r ; j < s.size() ; j++){
| ~~^~~~~~~~~~
shoes.cpp:45:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int j = r+1 ; j < s.size() ; j++){
| ~~^~~~~~~~~~
shoes.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int j = l ; j < s.size() ; j++){
| ~~^~~~~~~~~~
shoes.cpp:27:12: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
27 | ans += r-l-1;
| ~^~
# | 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... |