Submission #1021144

#TimeUsernameProblemLanguageResultExecution timeMemory
1021144vjudge1Arranging Shoes (IOI19_shoes)C++17
50 / 100
1072 ms4956 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using vi = vector <int>;

ll count_swaps (vi A) {
    vll ve(A.begin(), A.end());
    ll n = ve.size();
    vector <char> used(n, false);
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        if (used[i]) continue;
        ll x = -ve[i];
        ll j = i+1;
        ll cou = 0;
        while (j < n && (used[j] || ve[j] != x)) { cou += !used[j]; j++; }
        assert(j < n);
        assert(ve[i]+ve[j] == 0);
        used[i] = true;
        used[j] = true;
        ans += x < 0;
        ans += cou;
    }
    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...