이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <vector>
#include <algorithm>
using namespace std;
#define TRACE(x) cerr << #x << ' ' << x;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define pb push_back
const int MAXN = 100100;
int solve(vector <int> p, int start, int T) {
vector <int> pos;
vector <int> v[MAXN];
int n = p.size();
pos.resize(n);
int t = start;
REP(i, n) {
if (p[i]/abs(p[i]) == T) {
v[max(p[i], -p[i])].pb(t);
pos[i] = t;
t += 2;
}
}
REP(i, MAXN) reverse(v[i].begin(), v[i].end());
REP(i, n) {
if (p[i]/abs(p[i]) != T) {
int x = v[max(p[i], -p[i])].back();
v[max(p[i], -p[i])].pop_back();
if (p[i] < 0) x--;
else x++;
pos[i] = x;
}
}
long long inv = 0;
REP(i, n) REP(j, i) inv += (pos[i] < pos[j]);
return inv;
}
long long count_swaps(std::vector<int> s) {
return min(solve(s, 0, -1), solve(s, 1, 1));
}
# | 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... |