Submission #143249

#TimeUsernameProblemLanguageResultExecution timeMemory
143249daniel920712Arranging Shoes (IOI19_shoes)C++14
10 / 100
33 ms3832 KiB
#include <iostream> #include <stdio.h> #include <vector> #include <algorithm> #include <assert.h> using namespace std; int all[15]; int Find[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 { 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); if(now==ans2) for(i=0;i<N/2;i++) Find[i]=all[i]; }while(next_permutation(all,all+N/2));*/ 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(S[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(S[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; } } } return min(ans1,ans2); }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:77: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...