제출 #1138865

#제출 시각아이디문제언어결과실행 시간메모리
1138865AliyyiakbarArranging Shoes (IOI19_shoes)C++20
50 / 100
1096 ms1864 KiB
#include "shoes.h"
#include "bits/stdc++.h"
using namespace std;

long long count_swaps(vector<int> v)
{
    long long result = 0;
    int n = v.size();
    for (int i = 0; i < n; i += 2)
    {
        if (v[i] < 0)
        {
            int fl = -1;
            for (int j = i + 1; j < n; ++j)
            {
                if (-v[i] == v[j])
                {
                    fl = j;
                    break;
                }
            }
            for (int j = fl; j > i + 1; --j)
            {
                swap(v[j], v[j - 1]);
                result = 1LL * result + 1LL;
            }
        }
        else
        {
            int fl = -1;
            for (int j = i + 1; j < n; ++j)
            {
                if (-v[i] == v[j])
                {
                    fl = j;
                    break;
                }
            }
            for (int j = fl; j > i; --j)
            {
                swap(v[j], v[j - 1]);
                result = 1LL * result + 1;
            }
        }
    }
    return result;
}
#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...