Submission #1215342

#TimeUsernameProblemLanguageResultExecution timeMemory
1215342wazj2024Arranging Shoes (IOI19_shoes)C++20
30 / 100
1099 ms145896 KiB
#include "shoes.h"
#include "bits/stdc++.h"
using namespace std;
long long count_swaps(vector<int> s) {
    int n = s.size();
    vector<bool> used(n, false);
    map<int, queue<int>> pos;

    for (int i = 0; i < n; ++i) {
        pos[s[i]].push(i);
    }

    long long swaps = 0;

    for (int i = 0; i < n; ++i) {
        if (used[i]) continue;

        int val = s[i];
        int pair_pos = pos[-val].front(); pos[-val].pop();

        used[i] = true;
        used[pair_pos] = true;
        int count_used = 0;
        for (int j = i + 1; j < pair_pos; ++j) {
            if (used[j]) count_used++;
        }
        swaps += pair_pos - i - 1 - count_used;
        if (val > 0) swaps++;  
    }

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