Submission #153396

#TimeUsernameProblemLanguageResultExecution timeMemory
153396nandonathanielArranging Shoes (IOI19_shoes)C++14
85 / 100
33 ms2692 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL,LL> pii; vector<LL> neg[1005],pos[1005]; long long count_swaps(vector<int> s) { LL n=(LL)s.size()/2; if((LL)s.size()<=2000){ vector<LL> hasil; vector<pii> V; for(int i=0;i<s.size();i++){ if(s[i]<0)neg[abs(s[i])].push_back(i); else pos[s[i]].push_back(i); } for(int i=1;i<=n;i++){ for(int j=0;j<neg[i].size();j++){ V.push_back({min(neg[i][j],pos[i][j]),i}); } } sort(V.begin(),V.end()); for(auto isi : V){ hasil.push_back(-isi.second); hasil.push_back(isi.second); } LL res=0; for(LL i=0;i<s.size();i++){ LL no; for(LL j=i;j<s.size();j++){ if(s[j]==hasil[i]){ no=j; break; } } for(LL j=no;j>=i+1;j--){ swap(s[j],s[j-1]); res++; } } return res; } vector<int> v; for(int i=0;i<s.size();i++){ if(s[i]<0)v.push_back(i); } LL now=0,ans=0; for(int i=0;i<s.size();i++){ if(i%2==0){ ans+=abs(v[now]-i); now++; } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:14:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<s.size();i++){
               ~^~~~~~~~~
shoes.cpp:19:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<neg[i].size();j++){
                ~^~~~~~~~~~~~~~
shoes.cpp:29:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(LL i=0;i<s.size();i++){
              ~^~~~~~~~~
shoes.cpp:31:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(LL j=i;j<s.size();j++){
               ~^~~~~~~~~
shoes.cpp:45:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<s.size();i++){
              ~^~~~~~~~~
shoes.cpp:49:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<s.size();i++){
              ~^~~~~~~~~
shoes.cpp:30:7: warning: 'no' may be used uninitialized in this function [-Wmaybe-uninitialized]
    LL no;
       ^~
#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...