이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
#include "shoes.h"
ll count_swaps(vector<int> s) {
map<int, vector<int>> open, close;
vector<pair<int, int>> pairs;
for (int i = 0; i < (int)s.size(); ++i) {
if (s[i] < 0) {
open[abs(s[i])].push_back(i);
} else {
close[abs(s[i])].push_back(i);
}
}
for (auto xop : open) {
const vector<int> &op = xop.y;
const vector<int> &cl = close[xop.x];
assert(op.size() == cl.size());
for (int i = 0; i < (int)op.size(); ++i) {
pairs.emplace_back(op[i], cl[i]);
}
}
ll answer = 0;
for (auto &e : pairs) {
if (e.x > e.y) {
++answer;
swap(e.x, e.y);
}
// cout << "# " << e.x << " " << e.y << endl;
}
for (int i = 0; i < (int)pairs.size(); ++i) {
for (int j = i + 1; j < (int)pairs.size(); ++j) {
int a = pairs[i].x, b = pairs[i].y, c = pairs[j].x, d = pairs[j].y;
if (a > c) {
swap(a, c), swap(b, d);
}
assert(a < c);
assert(a < b && c < d);
if (a < b && b < c && c < d) {
answer += 0;
} else if (a < c && c < b && b < d) {
answer += 1;
} else if (a < c && c < d && d < b) {
answer += 2;
} else {
assert(false);
}
}
}
return answer;
}
#ifdef LC
#include "grader.cpp"
#endif
# | 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... |