Submission #149103

#TimeUsernameProblemLanguageResultExecution timeMemory
149103nandonathanielArranging Shoes (IOI19_shoes)C++14
30 / 100
1051 ms3580 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) { 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; }

Compilation message (stderr)

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