# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
532194 | bonk | Arranging Shoes (IOI19_shoes) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 2;
const int sus = 1e5;
ll count_swaps(vector<int>v){
ll n = v.size();
bool st2 = true;
ll ans = 0;
for(int i = 0; i < n/2; i++){
if(v[i] != -v[n/2 + i]){
st2 = false;
break;
}
}
if(st2){
ll x = (n/2)*(n/2 - 1)/2;
return x;
}
for(int i = 0; i < n; i++){
int cur = v[i];
int l = 1e9;
for(int j = i - 1; j >= 0; j--){
if(v[j] == -cur) l = j;
}
if(l != 1e9){
ans += (i - l) - (v[i] > 0);
for(int j = i; j > l; j--) swap(v[j], v[j - 1]);
v[l] = v[l + 1] = 0;
}
}
return ans;
}
int main(){
int n; cin >> n;
vector<int>arr(n);
for(int i = 0; i < n; i++) cin >> arr[i];
cout << count_swaps(arr) << endl;
return 0;
}