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"
#define all(x) x.begin(),x.end()
#define PB push_back
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 100100;
long long count_swaps(std::vector<int> s) {
if (sz(s) <= 2000) {
int n = sz(s) / 2;
ll ans = 0;
for (int i = 0; i < n; i++){
int loc = i + i;
int pos = -1;
for (int j = loc + 1; j < sz(s); j++)
if (s[j] == -s[loc]){
pos = j;
break;
}
assert(pos >= 0);
while (pos > loc + 1){
swap(s[pos], s[pos - 1]);
pos--;
ans++;
}
if (s[loc] > 0)
ans++;
}
return ans;
} else {
ll n = sz(s) / 2;
return n * (n - 1ll) / 2ll;
}
}
# | 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... |