제출 #1292567

#제출 시각아이디문제언어결과실행 시간메모리
1292567lukaye_19Arranging Shoes (IOI19_shoes)C++20
15 / 100
13 ms1968 KiB
#include <bits/stdc++.h>
using namespace std;

long long count_swaps(vector<int> Shoes) 
{
    long long n = Shoes.size() / 2;
    
    bool LeftRightShoes = true;
    
    for (int i = 0; i < n; i++) 
    {
        if (Shoes[i] > 0) 
        {
            LeftRightShoes = false;
            
            break;
        }
    }
    
    if (LeftRightShoes) 
    {
        for (int i = n; i < 2 * n; i++) 
        {
            if (Shoes[i] < 0) 
            {
                LeftRightShoes = false;
                
                break;
            }
        }
    }
    
    if (LeftRightShoes) 
    {
        return (n * (n - 1)) / 2;
    }

    long long Answer = 0;

    while (Shoes.size() != 0) 
    {
        int FirstShoe = Shoes[0];
        int Matching = -FirstShoe;

        int Dist = 0;
        
        auto it = Shoes.begin() + 1;

        while (*it != Matching) 
        {
            ++it;
            
            Dist++;
        }

        Shoes.erase(it);
        Shoes.erase(Shoes.begin());

        Answer += Dist;

        if (FirstShoe < 0) 
        {
            Answer++;
        }
    }

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