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>
using namespace std;
long long N;
pair<long long,long long> A[100005], B[100005];
long long count_swaps(vector<int> s) {
N = s.size()/2;
long long ans = 0;
for (long long i = 0; i < N; ++i) {
for (long long j = 0; j < N; ++j) A[j] = B[j] = make_pair(4e18,4e18);
long long cnt = 0;
for (long long j = 0; j < N*2; ++j) {
if (s[j] == 0) continue;
if (s[j] > 0) A[s[j]-1] = min(A[s[j]-1],make_pair(cnt++,j));
else B[-s[j]-1] = min(B[-s[j]-1],make_pair(cnt++,j));
}
pair<long long,long long> x = make_pair(4e18,4e18);
for (long long j = 0; j < N; ++j) if (A[j].first != -1 && B[j].first != -1) {
long long val = A[j].first + B[j].first;
if (B[j].first < A[j].first) val--;
x = min(x,make_pair(val,j));
}
ans += x.first;
s[A[x.second].second] = s[B[x.second].second] = 0;
}
return ans;
}
# | 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... |