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;
typedef long long ll;
typedef pair<int, int> pll;
#define X first
#define Y second
#define sep ' '
map<int, vector<pll>> mp;
ll count_swaps(vector<int> vec) {
ll ans = 0;
for (int i = 0; i < int(vec.size()); i++)
mp[abs(vec[i])].push_back({i, int(vec[i] > 0)});
for (auto [_, e] : mp) {
vector<pll> vec;
for (auto [x, y] : e) {
if (!vec.empty() && y != vec.back().Y) {
ans += x - vec.back().X - 1 + (y ^ 1);
vec.pop_back();
} else vec.push_back({x, y});
}
}
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... |