Submission #1204656

#TimeUsernameProblemLanguageResultExecution timeMemory
1204656tapilyocaArranging Shoes (IOI19_shoes)C++20
45 / 100
15 ms3760 KiB
#include "shoes.h"
#include<bits/stdc++.h>
using namespace std;

template<typename T>
using vec = vector<T>;
using ll = long long;
using vll = vec<ll>;
using pll = pair<ll,ll>;
#define pb push_back


long long count_swaps(std::vector<int> s) {
    ll n = s.size()>>1;
    ll out = 0;

    vll oop1, oop2;

    for(int i = 0; i < 2*n; i++) {
        if(s[i] < 0 and i%2) {
            oop1.pb(i);
        } else if(s[i] > 0 and i%2 == 0) {
            oop2.pb(i);
        }
    }


    assert(oop1.size() == oop2.size());

    for(int i = 0; i < oop1.size(); i++) {
        out += abs(oop1[i] - oop2[i]);
    }
    return out;
}


#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...