제출 #392025

#제출 시각아이디문제언어결과실행 시간메모리
392025AugustinasJucasArranging Shoes (IOI19_shoes)C++14
50 / 100
1084 ms14844 KiB
#include <bits/stdc++.h>
using namespace std;

const int dydis = 1e5  + 1;
vector<int> kurL[dydis];
vector<int> kurR[dydis];
long long count_swaps(vector<int> s) {

    for(int i = 0; i < s.size(); i++){
        if(s[i] > 0) kurR[s[i]].push_back(i);
        else kurL[-s[i]].push_back(i);
    }
    vector<pair<pair<int, int>, int> > poros;
    int n = s.size()/2;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < kurL[i].size(); j++){
            if(kurL[i][j] < kurR[i][j]){
                poros.push_back({{kurL[i][j], kurR[i][j]}, 0});
            }else{
                poros.push_back({{kurR[i][j], kurL[i][j]}, 1});
            }
        }
    }
    sort(poros.begin(), poros.end());
    reverse(poros.begin(), poros.end());

    int realIndex[s.size() + 1];
    for(int i = 0; i < s.size(); i++) realIndex[i] = i;
    long long ans = 0;
    for(auto x : poros){
        int i1 = realIndex[x.first.first];
        int i2 = realIndex[x.first.second] - 1 + x.second;
//        cout << "i1 = " << i1 << ", i2 = " << i2 << endl;
        ans += i2-i1;
        for(int i = x.first.first+1; i <= x.first.second-1 + x.second; i++){
            realIndex[i]--;
        }
    }


	return ans;
}

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

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