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 <iostream>
#include <vector>
#include <cstdio>
#define rep(i,a,b) for(int i = a; i<b; i++)
#define per(i,a,b) for(int i = a; i>b; i--)
#define pb push_back
using namespace std;
long long count_swaps(vector<int> s) {
int n = s.size();
long long ans = 0;
rep(i,0,n){
if(s[i]<0){
int pos;
rep(j,i+1,n){
if((-s[i]) == s[j]){
pos = j;
break;
}
}
per(j,pos, i+1){
swap(s[j], s[j-1]);
ans++;
}
}else{
int pos;
rep(j,i+1,n){
if((-s[i]) == s[j]){
pos = j;
break;
}
}
per(j,pos, i){
swap(s[j], s[j-1]);
ans++;
}
}
//cout << s[i] << endl;
i++;
}
//cout << "ans: " << ans << endl;
return ans;
}
Compilation message (stderr)
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:26:8: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
26 | int pos;
| ^~~
shoes.cpp:14:8: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
14 | int pos;
| ^~~
# | 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... |