Submission #143263

#TimeUsernameProblemLanguageResultExecution timeMemory
143263daniel920712Arranging Shoes (IOI19_shoes)C++14
10 / 100
35 ms3640 KiB
#include <iostream> #include <stdio.h> #include <vector> #include <algorithm> #include <assert.h> using namespace std; 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=0,ans3=1e18,ans4=1e18,N=S.size(),i,j,k,now=0; long long t; 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) { t=0-S1[j]; for(k=j;k>2*i;k--) { ans1++; swap(S1[k],S1[k-1]); } break; } } for(j=2*i+1;j<N;j++) { if(S1[j]==t) { for(k=j;k>2*i+1;k--) { ans1++; swap(S1[k],S1[k-1]); } break; } } } ans2=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) { t=0-S1[j]; break; } } for(j=2*i;j<N;j++) { if(S1[j]==t) { for(k=j;k>2*i;k--) { ans2++; swap(S1[k],S1[k-1]); } break; } } for(j=2*i+1;j<N;j++) { if(S1[j]==0-t) { for(k=j;k>2*i+1;k--) { ans2++; swap(S1[k],S1[k-1]); } break; } } } ans3=0; for(i=0;i<N;i++) S1[i]=S[i]; for(i=0;i<N/2;i++) { for(j=N-2*i-1;j>=0;j--) { if(S1[j]>0) { t=0-S1[j]; for(k=j;k<N-2*i-1;k++) { ans3++; swap(S1[k],S1[k+1]); } break; } } for(j=N-2*i-2;j>=0;j--) { if(S1[j]==t) { for(k=j;k<N-2*i-2;k++) { ans3++; swap(S1[k],S1[k+1]); } break; } } /*for(j=0;j<N;j++) printf("%d ",S1[j]); printf("\n");*/ } //printf("%lld %lld %lld\n",ans1,ans2,ans3); return min(min(ans1,ans2),min(ans3,ans4)); }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:15:66: warning: unused variable 'now' [-Wunused-variable]
     long long ans1=0,ans2=0,ans3=1e18,ans4=1e18,N=S.size(),i,j,k,now=0;
                                                                  ^~~
shoes.cpp:107:13: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
             if(S1[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...