제출 #289809

#제출 시각아이디문제언어결과실행 시간메모리
289809IgorIArranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms384 KiB
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <cstdlib>
#include <iostream>
#include <map>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int (i) = 0; (i) < (n); (i)++)

long long count_swaps(vector<int> a)
{
    long long ans = 0;
    int n = a.size();
    for (int i = 0; i < n; i += 2)
    {
        map<int, int> hv;
        int p1 = 0, p2 = 0;
        for (int j = i; j < n; j++)
        {
            hv[a[j]] = j;
            if (hv.find(-a[j]) != hv.end())
            {
                p1 = hv[-a[j]];
                p2 = j;
                break;
            }
        }
        while (p1 != i)
        {
            swap(a[p1 - 1], a[p1]);
            p1--;
            ans++;
        }
        while (p2 != i + 1)
        {
            swap(a[p2 - 1], a[p2]);
            p2--;
            ans++;
        }
        if (a[p1] > a[p2])
        {
            swap(a[p1], a[p2]);
            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...