# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
253516 | Badrangiikh | Arranging Shoes (IOI19_shoes) | C++14 | 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>
#include <deque>
#include <cmath>
using namespace std;
#define ll long long
/*freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/
long long m , s1 , s2 , y ;
long long count_swaps ( vector < int > s ) {
long long n = s . size ( ) ;
if ( n == 2 ) {
if ( s [ 0 ] < s [ 1 ] ) return 0 ;
else return 1 ;
}
long long x = 0 ;
for ( long long i = 1 ; i < n ; i ++ ) {
if ( abs ( s [ i ] ) == abs ( s [ 0 ] ) ) x ++ ;
}
if ( x + 1 == n ) {
long long y = 0 ;
long long z = 0 ;
for ( long long i = 0 ; i < n ; i ++ ) {
if ( s [ i ] < 0 ) {
z += abs ( i - y ) ;
y += 2 ;
}
}
return z ;
}
x = 0 ;
y = 0 ;
n = s . size ( ) / 2 ;
m = s . size ( ) ;
for ( int l = 1 ; l <= n ; l ++ ) {
for ( int i = 0 ; i < m ; i ++ ) {
if ( s [ i ] < 0 ) {
for ( int j = 0 ; j < m ; j ++ ) {
if ( s [ j ] == ( -1 ) * s [ i ] ) {
s1 = i ;
s2 = j ;
break ;
}
}
break ;
}
}
if ( s1 < s2 ) {
x += ( s1 + s2 - 1 ) ;
}
else {
x += ( s1 + s2 ) ;
}
y = 0 ;
for ( i = 0 ; i < m ; i ++ ) {
if ( i == s1 || i == s2 ) continue ;
s [ y ] = s [ i ] ;
}
m -= 2 ;
}
return x ;
}