이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define fi first
#define se second
ll count_swaps(vector<int> s) {
int n = s.size();
vector<int> rel(n);
deque<int> occ[n+1] = {};
deque<pii> leftShoes;
for (int i = 0; i < n; i++) {
if (s[i] < 0) leftShoes.push_back({i, -s[i]});
else occ[s[i]].push_back(i);
}
int placed = 0;
for (auto &[idx, typ] : leftShoes) {
rel[idx] = placed++;
rel[occ[typ].front()] = placed++;
occ[typ].pop_front();
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i; j > 0; j--) {
if (rel[j] < rel[j-1]) {
swap(rel[j], rel[j-1]);
ans++;
}
}
}
return ans;
}
// Grader
#ifdef Zanite
int main() {
int n;
assert(1 == scanf("%d", &n));
vector<int> S(2 * n);
for (int i = 0; i < 2 * n; i++)
assert(1 == scanf("%d", &S[i]));
fclose(stdin);
long long result = count_swaps(S);
printf("%lld\n", result);
fclose(stdout);
return 0;
}
#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... |