Submission #1257016

#TimeUsernameProblemLanguageResultExecution timeMemory
1257016kawhietArranging Shoes (IOI19_shoes)C++20
10 / 100
1 ms328 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;

long long count_swaps(vector<int> a) {
    int n = a.size();
    long long res = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] < 0) {
            continue;
        }
        if (i > 0 && a[i] == -a[i - 1]) {
            continue;
        }
        for (int j = i + 1; j < n; j++) {
            if (a[j] == -a[i]) {
                for (int k = j; k > i; k--) {
                    res++;
                    swap(a[k], a[k - 1]);
                }
                break;
            }
        }
    }
    return res;
}
#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...