Submission #253479

#TimeUsernameProblemLanguageResultExecution timeMemory
253479BadrangiikhArranging Shoes (IOI19_shoes)C++14
10 / 100
1085 ms2040 KiB
#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);*/
 
int count_swaps ( vector < int > s ) {
    int n = s . size ( ) ;
    if ( n == 2 ) {
        if ( s [ 0 ] < s [ 1 ] ) return 0 ;
        else return 1 ;
    }
    int x = 0 ;
    for ( int 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 ( int i = 0 ; i < n ; i ++ ) {
            if ( s [ i ] < 0 ) {
                z += abs ( i - y ) ;
                y += 2 ;
            } 
        }
        return z ;
    }
    x = 0 ;
  	long long y = 0 ;
    while ( n > 0 ) {
        for ( int i = 0 ; i < n ; i ++ ) {
            if ( s [ i ] < 0 ) {
                x += i ;
                y = abs ( s [ i ] ) ;
                s . erase ( s . begin ( ) + i ) ;
              	n -- ;
                for ( int j = 0 ; j < n ; j ++ ) {
                    if ( s [ j ] == y ) {
                        x += j ;
                        s . erase ( s . begin ( ) + j ) ;
                      	n -- ;
                        break ;
                    }
                }
                break ;
            }
        }
    }
    return x ;
}    
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...