Submission #161723

#TimeUsernameProblemLanguageResultExecution timeMemory
161723andrewArranging Shoes (IOI19_shoes)C++17
50 / 100
1072 ms4008 KiB
#include <bits/stdc++.h>
#include "shoes.h"

#define fi first
#define sz(x) (int)x.size()
#define se second
#define pll pair <ll,ll>
#define pii pair <int,int>

using namespace std;
typedef long long ll;
typedef long double ld;
const ll N = 2e5;

long long count_swaps(vector<int> s) {
    ll n = sz(s) / 2, ans = 0;
    vector <int> b = s;

    for(int i = 0; i < n * 2; i += 2){
        if(b[i] < 0){
            int j = i + 1;
            while(-b[j] != b[i])j++;
            while(j > i + 1)swap(b[j], b[j - 1]), j--, ans++;
        }else{
            int j = i + 1;
            while(-b[j] != b[i])j++;
            while(j > i)swap(b[j], b[j - 1]), j--, ans++;
        }
    }

	return ans;
}
#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...