Submission #65066

#TimeUsernameProblemLanguageResultExecution timeMemory
65066Bodo171Sorting (IOI15_sorting)C++14
100 / 100
582 ms19488 KiB
#include "sorting.h" #include <iostream> const int nmax=200005; using namespace std; int i,n,idx,u; int en[nmax],v[nmax],p[nmax],poz[nmax],a[3*nmax],b[3*nmax],A[3*nmax],B[3*nmax]; bool check(int val) { for(i=0;i<n;i++) poz[v[i]]=i,p[i]=v[i]; for(i=0;i<val;i++) swap(v[a[i]],v[b[i]]); for(i=0;i<n;i++) en[v[i]]=i;//en[i]-pozitia pe care ajunge elementul i; idx=0;u=0; for(i=0;i<val;i++) { swap(p[a[i]],p[b[i]]); swap(poz[p[a[i]]],poz[p[b[i]]]); while(idx<n&&en[idx]==idx) idx++; if(idx<n) { en[v[idx]]=en[idx];//acum elementul care era pe pozitia noastra ajunge unde ar fi ajuns al noostru v[en[idx]]=v[idx];//facem asta si la nivelul sirului A[u]=poz[idx];B[u]=poz[v[idx]]; ++u; swap(poz[idx],poz[v[idx]]); swap(p[poz[idx]],p[poz[v[idx]]]); idx++; } } while(idx<n&&en[idx]==idx) idx++; return (idx==n); } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int ans=M; n=N; for(i=0;i<M;i++) a[i]=X[i],b[i]=Y[i]; for(int p=19;p>=0;p--) { for(i=0;i<N;i++) v[i]=S[i]; if(ans-(1<<p)>=0&&check(ans-(1<<p))) ans-=(1<<p); } for(i=0;i<N;i++) v[i]=S[i]; int okceva=check(ans); for(i=0;i<u;i++) P[i]=A[i],Q[i]=B[i]; for(i=u;i<ans;i++) P[i]=Q[i]=0; return ans; }

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:40:13: warning: declaration of 'p' shadows a global declaration [-Wshadow]
     for(int p=19;p>=0;p--)
             ^
sorting.cpp:6:22: note: shadowed declaration is here
 int en[nmax],v[nmax],p[nmax],poz[nmax],a[3*nmax],b[3*nmax],A[3*nmax],B[3*nmax];
                      ^
sorting.cpp:52:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(i=u;i<ans;i++)
     ^~~
sorting.cpp:54:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  return ans;
  ^~~~~~
sorting.cpp:49:9: warning: unused variable 'okceva' [-Wunused-variable]
     int okceva=check(ans);
         ^~~~~~
#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...