Submission #751351

#TimeUsernameProblemLanguageResultExecution timeMemory
751351kusmetliqArranging Shoes (IOI19_shoes)C++14
85 / 100
373 ms3132 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; long long count_swaps(vector<int> a) { if(a.size()<=2000) { int n=a.size()/2; long long ans=0; while(a.size()>0) { map<int,int>m; for(int i=0; i<a.size(); i++) { if(m[a[i]]==0)m[a[i]]=i+1; } int minscore=2*n; int scoreval=0; for(int i=1; i<=n+69; i++) { if(m[i]==0)continue; int updscore=0; updscore+=m[i]-1; updscore+=m[-i]-1; if(m[-i]<m[i])updscore--; if(updscore<minscore) { minscore=updscore; scoreval=i; } } ans+=minscore; a.erase(find(a.begin(),a.end(),scoreval)); a.erase(find(a.begin(),a.end(),-scoreval)); } return ans; } else { int n=a.size(); int curcnt=0; long long ans=0; for(int i=0; i<a.size(); i++) { if(a[i]<0) { ans+=abs(i-(curcnt*2)); curcnt++; } } return ans; } }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:10:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |             for(int i=0; i<a.size(); i++) {
      |                          ~^~~~~~~~~
shoes.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(int i=0; i<a.size(); i++) {
      |                      ~^~~~~~~~~
shoes.cpp:32:13: warning: unused variable 'n' [-Wunused-variable]
   32 |         int n=a.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...