# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
295381 | tzero | Arranging Shoes (IOI19_shoes) | C++14 | 41 ms | 3200 KiB |
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 <iostream>
#include <vector>
#include <math.h>
#include <cassert>
using namespace std;
using ll = long long;
ll count_swaps(vector<int> s) {
int n = (int)s.size();
bool same_size = true;
for(int i = 0; i < n; i++) {
if(i > 0 && abs(s[i]) != abs(s[i - 1])) same_size = false;
}
if(n == 2) {
if(s[0] < 0) return 0;
else return 1;
} else if(same_size) {
ll move_left = 0, move_right = 0;
int found_left = 0, found_right = 0;
for(int i = 0; i < n; i++) {
if(s[i] < 0) {
int pos = found_left * 2;
move_left += abs(i - pos);
found_left++;
} else {
int pos = found_right * 2 + 1;
move_right += abs(i - pos);
found_right++;
}
}
return min(move_left, move_right);
} else {
return -1;
}
}
int _main() {
int n;
scanf("%d", &n);
vector<int> _s(2 * n);
for(int i = 0; i < n; i++) {
scanf("%d", &_s[i]);
}
printf("%lld\n", count_swaps(_s));
return 0;
}
Compilation message (stderr)
# | 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... |