Submission #135285

#TimeUsernameProblemLanguageResultExecution timeMemory
135285BoxworldSorting (IOI15_sorting)C++14
20 / 100
17 ms860 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int R=0; for (int i=0;i<N;i++) for (int j=i+1;j<N;j++) if (S[i]>S[j])R++; if (R==0)return 0; for (int i=0;i<M;i++){ int p1,p2,start=0,ok=1; for (int j=0;j<N;j++) if (S[j]==X[i]){p1=j;break;} for (int j=0;j<N;j++) if (S[j]==Y[i]){p2=j;break;} // printf("SWAP**:S[%d]=%d S[%d]=%d\nNOW:",p1,S[p1],p2,S[p2]); swap(S[p1],S[p2]); // for (int i=0;i<N;i++)printf("%d ",S[i]);printf("\n"); if (p1+p2==1&&S[p1]+S[p2]==1)start=2; for (int j=start;j<N-1;j++) if (S[j]!=j){ P[i]=j;Q[i]=S[j]; // printf("SWAP%d:S[%d]=%d S[%d]=%d\nNOW:",i,j,S[j],S[j],S[S[j]]); swap(S[j],S[S[j]]); // for (int i=0;i<N;i++)printf("%d ",S[i]);printf("\n"); ok=0; break; } if (ok){ if (S[0]>S[1]){ P[i]=0;Q[i]=1; // printf("SWAP%d:S[%d]=%d S[%d]=%d\nNOW:",i,0,S[0],1,S[1]); swap(S[0],S[1]); // for (int i=0;i<N;i++)printf("%d ",S[i]);printf("\n"); return i; }else { P[i]=0; Q[i]=0; return i; } } } }

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:44:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
sorting.cpp:12:16: warning: 'p2' may be used uninitialized in this function [-Wmaybe-uninitialized]
         int p1,p2,start=0,ok=1;
                ^~
sorting.cpp:12:13: warning: 'p1' may be used uninitialized in this function [-Wmaybe-uninitialized]
         int p1,p2,start=0,ok=1;
             ^~
#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...