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<bits/stdc++.h>
#include "shoes.h"
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
ll count_swaps(vi s) {
ll ats = 0;
int N = (int)s.size();
for (int i = 0; i < N; ++i)
{
if (s[i] > 0) {
int nx = i + 1;
while (s[nx] > 0) nx++;
int val = s[nx];
s.erase(s.begin() + nx);
s.insert(s.begin() + i, val);
ats += nx - i;
}
assert(s[i] < 0);
// s[i] < 0
int nx = i + 1;
while (-s[i] != s[nx]) nx++;
ats += nx - (i + 1);
s.erase(s.begin() + nx);
s.insert(s.begin() + i + 1, -s[i]);
i++;
}
return ats;
}
# | 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... |