| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 216999 | thatprogrammer | Arranging Shoes (IOI19_shoes) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
