Submission #889090

#TimeUsernameProblemLanguageResultExecution timeMemory
889090Lincito_31Arranging Shoes (IOI19_shoes)C++14
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; long long x=0; long long count_swaps(vector<int> s) { vector<pair<int,int>> par_posi; vector<pair<int,int>> par_nega; for(int i=0;i<s.size();i++){ if(s[i]>0){ par_posi.push_back(make_pair(s[i],i)); }else{ par_nega.push_back(make_pair(s[i],i)); } } sort(par_posi.begin(),par_posi.end()); sort(par_nega.begin(),par_nega.end()); int parencontrado=0; while(!s.empty()){ int ini=0,fin=par_posi.size()-1,mitad; int temp=s[0]; if(temp<0){ mitad=(ini+fin)/2; while(par_posi[mitad].first!=-temp){ if(par_posi[mitad].first>-temp){ fin=mitad-1; }else{ ini=mitad+1; } } x+=par_posi[mitad].second-1-parencontrado; //s.erase(s.begin()+par_posi[mitad].second); s.erase(s.begin()); par_posi.erase(par_posi.begin()+mitad); //parencontrado++; }else{ mitad=(ini+fin)/2; while(par_nega[mitad].first!=-temp){ if(par_nega[mitad].first<-temp){ ini=mitad++; }else{ fin=mitad--; } } x+=par_nega[mitad].second-parencontrado; //s.erase(s.begin()+par_nega[mitad].second); s.erase(s.begin()); par_nega.erase(par_nega.begin()+mitad); //parencontrado++; } } return x; }

Compilation message (stderr)

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