Submission #143143

#TimeUsernameProblemLanguageResultExecution timeMemory
143143daniel920712Arranging Shoes (IOI19_shoes)C++14
10 / 100
33 ms3580 KiB
#include <iostream> #include <stdio.h> #include <vector> #include <algorithm> #include <assert.h> using namespace std; int all[15]; int S1[1005]; bool F(int a,int b) { return a<b; } long long count_swaps(std::vector<int> S) { long long ans1=0,ans2=1e18,N=S.size(),i,j,k,now=0; long long t; for(i=0;i<N;i++) if(S[i]>0) all[now++]=S[i]; sort(all,all+N/2,F); do { /*for(i=0;i<N;i++) printf("%d ",all[i]); printf("\n");*/ now=0; for(i=0;i<N;i++) S1[i]=S[i]; for(i=0;i<N/2;i++) { for(j=2*i;j<N;j++) { if(S1[j]==0-all[i]) { for(k=j;k>2*i;k--) { now++; swap(S1[k],S1[k-1]); } break; } } for(j=2*i+1;j<N;j++) { if(S1[j]==all[i]) { for(k=j;k>2*i+1;k--) { now++; swap(S1[k],S1[k-1]); } break; } } } ans2=min(ans2,now); }while(next_permutation(all,all+N/2)); for(i=0;i<N/2;i++) { for(j=2*i;j<N;j++) { if(S[j]<0) { t=0-S[j]; for(k=j;k>2*i;k--) { ans1++; swap(S[k],S[k-1]); } break; } } for(j=2*i+1;j<N;j++) { if(S[j]==t) { for(k=j;k>2*i+1;k--) { ans1++; swap(S[k],S[k-1]); } break; } } } //printf("%lld %lld\n",ans1,ans2); assert(ans1<=ans2); return ans2; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:74:13: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
             if(S[j]==t)
             ^~
#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...