이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
long long count_swaps(std::vector<int> s) {
long long ans = 0;
int n = s.size() / 2;
vector<pair<int, int>> a;
vector<int> adj[n + 1];
for (int i = 0; i < 2 * n; i++){
if (s[i] < 0) {
a.push_back({-s[i], i});
} else {
adj[s[i]].push_back(i);
}
}
for (int i = 1; i <= n; i++) reverse(adj[i].begin(), adj[i].end());
vector <int> realpos(2 * n, -1);
int pos = 0;
for (auto [x, y] : a){
realpos[y] = pos;
realpos[adj[x].back()] = pos + 1;
adj[x].pop_back();
pos += 2;
}
// for (int i = 0; i < 2 * n; i++) cout << realpos[i] << " ";
// cout << "\n";
for (int i = 0; i < 2 * n; i++){
for (int j = i + 1; j < 2 * n; j++){
if (realpos[j] < realpos[i]) ans++;
}
}
return ans;
}
// int main(){
// int n; cin >> n;
// vector <int> a(n);
// for (auto &x : a) cin >> x;
// cout << count_swaps(a) << "\n";
// return 0;
// }
# | 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... |