Submission #164446

#TimeUsernameProblemLanguageResultExecution timeMemory
164446cfalasArranging Shoes (IOI19_shoes)C++14
10 / 100
2 ms376 KiB
#include<bits/stdc++.h> using namespace std; #include "shoes.h" #define F first #define S second long long count_swaps(std::vector<int> s) { int n = s.size()/2; int swaps=0; int ind = 0; map<int, vector<int> > m; for(int i=0;i<s.size();i++){ m[s[i]].push_back(i); } while(ind<s.size()){ if(m[s[ind]].size()==0 || m[s[ind]][0]!=ind){ ind++; continue; } if(s[ind]>0) swaps++; if(m[-s[ind]].size()==0) while(1) {} int i = m[-s[ind]][0]; swaps += (i-ind-1); m[-s[ind]].erase(m[s[i]].begin()); m[s[ind]].erase(m[s[ind]].begin()); ind++; } return swaps; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:12:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<s.size();i++){
              ~^~~~~~~~~
shoes.cpp:15:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(ind<s.size()){
        ~~~^~~~~~~~~
shoes.cpp:8:6: warning: unused variable 'n' [-Wunused-variable]
  int n = s.size()/2;
      ^
#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...