# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
216999 | thatprogrammer | Arranging Shoes (IOI19_shoes) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
if (fopen("input.in", "r")) {
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
}
int n;
cin >> n;
int s[100000];
for (int i = 0; i < 2 * n; i++) {
cin >> s[i];
}
ll ans = 0;
for (int i = 0; i < 2 * n; i += 2) {
int j;
for (j = i + 1; j < 2 * n; j++) {
if (s[j] == -s[i]) break;
}
if (s[i] < 0)
ans += j - i - 1;
else
ans += j - i;
for (; j > i; j--) swap(s[j], s[j - 1]);
}
cout << ans << endl;
}