Submission #151165

#TimeUsernameProblemLanguageResultExecution timeMemory
151165nandonathanielArranging Shoes (IOI19_shoes)C++14
65 / 100
34 ms3836 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; typedef long long LL; LL a[100],V[100]; long long count_swaps(vector<int> s) { if((LL)s.size()<=16){ LL n=(LL)s.size(),now=0; n/=2; for(LL i=0;i<s.size();i++){ if(s[i]>0){ now++; a[now]=s[i]; V[now]=now; } } vector<int> t=s; LL ans=1e18; do{ s=t; LL res=0; vector<LL> hasil; for(LL i=1;i<=n;i++){ hasil.push_back(-a[V[i]]); hasil.push_back(a[V[i]]); } //for(LL i=1;i<=2*n;i++)cout << hasil[i-1] << endl; 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++; } } ans=min(ans,res); }while(next_permutation(V+1,V+n+1)); return ans; } vector<int> v; for(int i=0;i<s.size();i++){ if(s[i]<0)v.push_back(i); } long long 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:12:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(LL i=0;i<s.size();i++){
              ~^~~~~~~~~
shoes.cpp:30:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(LL i=0;i<s.size();i++){
               ~^~~~~~~~~
shoes.cpp:32:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(LL j=i;j<s.size();j++){
                ~^~~~~~~~~
shoes.cpp:48:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<s.size();i++){
              ~^~~~~~~~~
shoes.cpp:52:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<s.size();i++){
              ~^~~~~~~~~
shoes.cpp:31:8: 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...