Submission #143125

#TimeUsernameProblemLanguageResultExecution timeMemory
143125legendArranging Shoes (IOI19_shoes)C++17
10 / 100
2 ms376 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;

long long count_swaps(std::vector<int> s) {
	set<pair<int,int> > ms;
    map<int,int> pos;
	for(int i = 0;i<s.size();i++){
            if(s[i]<0) ms.insert({i,s[i]});
            pos[s[i]] = i;
	}
    int ps = 0;
    long long ans = 0;
    while(ps<s.size()){
        pair<int,int> x = *(ms.begin());
        ms.erase(ms.begin());
        ans+=(x.first-ps);
        for(int i = ps;i<x.first;i++){
            int u = s[i];
            pos[u]++;
        }
        for(int i = x.first;i>ps;i--){
            swap(s[i],s[i-1]);
        }
        for(int i = ps+1;;i++){
            if(s[i] == -x.second){
                ans+=(i-ps-1);
                for(int j = i;j>ps+1;j--) swap(s[j],s[j-1]);
                break;
            }

        }
      //  cout<<ans<<endl;
        ps+=2;
    }
    return ans;
	return 1;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:8:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i<s.size();i++){
                ~^~~~~~~~~
shoes.cpp:14:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(ps<s.size()){
           ~~^~~~~~~~~
#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...