제출 #332323

#제출 시각아이디문제언어결과실행 시간메모리
332323blueArranging Shoes (IOI19_shoes)C++17
0 / 100
28 ms3180 KiB
#include "shoes.h"
#include <vector>
using namespace std;

long long count_swaps(vector<int> S)
{
    int n = S.size()/2;
    return (n-1)*n/2;

    long long res = 0;

    vector<int> left[n+1], right[n+1];

    vector<int> othershoe(2*n, -1);

    for(int i = 0; i < 2*n; i++)
    {
        if(S[i] < 0) left[-S[i]].push_back(i);
        else right[S[i]].push_back(i);
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j < left[i].size(); j++)
        {
            if(left[i][j] < right[i][j]) othershoe[left[i][j]] = right[i][j];
            else
            {
                othershoe[right[i][j]] = left[i][j];
                res++;
            }
        }
    }

    vector<int> leftshift(2*n, 0);
    long long lshift = 0;
    for(int i = 0; i < 2*n; i++)
    {
        lshift += leftshift[i];
        leftshift[othershoe[i] + 1]++;
        res += (long long)(othershoe[i] - i - 1 - lshift);
    }
    return res;
}

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:23:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for(int j = 0; j < left[i].size(); j++)
      |                        ~~^~~~~~~~~~~~~~~~
#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...