| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1305499 | ayaz | Arranging Shoes (IOI19_shoes) | C++20 | 0 ms | 0 KiB |
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define isz(x) (int)x.size()
long long count_swaps(std::vector<int> s) {
vector<int> a = s;
int n = isz(a);
if (n == 2) {
return (a[0] > 0);
}
int ans = 0;
for (int i = 0; i < n; i++) {
int d = 1e9;
for (int j = n - 1; j >= 0; j--) {
if (a[i] + a[j] == 0 && abs(d - i) >= abs(j - i)) {
d = j;
}
}
if (d == i + 1 || d == i - 1) continue;
int v = a[d];
a.erase(a.begin() + d);
if (d < i)
a.insert(a.begin() i, v);
else
a.insert(a.begin() + 1 + i, v);
ans += (d > i ? d - (i + 1) : (i - 1) - d);
// for( auto j : a) cout << j << ' ';
// cout << '\n';
}
for (int i = 0; i < n; i += 2) {
ans += (a[i] > 0);
}
return ans;
}
