# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
959438 | NemanjaSo2005 | 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 "shoes.h"
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e5+5;
int N,niz[maxn];
ll res=0;
int prvalev(){
for(int i=1;i<=N;i++)
if(niz[i]<0)
return i;
}
int parod(int x){
for(int i=1;i<=N;i++)
if(niz[i]==-x)
return i;
}
void zamena(int y,int x){
for(int i=y;i>x;i--){
res++;
swap(niz[i],niz[i-1]);
}
}
ll count_swaps(vector<int> s) {
N=s.size();
return (N/2-1)*(N/2);
for(int i=0;i<N;i++)
niz[i+1]=s[i];
for(int i=1;i<=N;i+=2){
int pl=prvalev();
zamena(pl,i);
int pd=parod(niz[i]);
// cout<<pl<<" "<<pd<<endl;
zamena(pd,i+1);
niz[i]=niz[i+1]=0;
}
return res;
}
#include <cstdio>
#include <cassert>
using namespace std;
int main() {
int n;
assert(1 == scanf("%d", &n));
vector<int> S(2 * n);
for (int i = 0; i < 2 * n; i++)
assert(1 == scanf("%d", &S[i]));
fclose(stdin);
long long result = count_swaps(S);
printf("%lld\n", result);
fclose(stdout);
return 0;
}