Submission #408818

#TimeUsernameProblemLanguageResultExecution timeMemory
408818MDarioSorting (IOI15_sorting)C++11
36 / 100
2 ms1100 KiB
#include "sorting.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second int n, s[200001], m, x[600001], y[600001]; bool f(ll xf){ int s1[200001]; for(int i=0; i<n; i++){ s1[i]=s[i]; } int c=0; for(int i=0; i<xf; i++){ swap(s1[x[i]], s1[y[i]]); } for(int i=0; i<n; i++){ while(s1[i]!=i){ c++; swap(s1[i], s1[s1[i]]); } } return (c<=xf); } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n=N; m=M; bool b=1; for(int i=0; i<n; i++){ s[i]=S[i]; if(S[i]!=i)b=0; } if(b)return 0; for(int i=0; i<n; i++){ x[i]=X[i]; y[i]=Y[i]; } int l=0, r=n+1, mid=0; while(l+1<r){ mid=(l+r)/2; if(f(mid)){ r=mid; } else l=mid; } int c=0; l++; int s1[n], p[n]; for(int i=0; i<n; i++){ s1[i]=i; p[i]=i; } for(int i=0; i<l; i++){ swap(S[x[i]], S[y[i]]); swap(s1[x[i]], s1[y[i]]); swap(p[x[i]], p[y[i]]); } for(int i=0; i<n; i++){ while(S[i]!=i){ swap(s1[p[x[c]]], s1[p[y[c]]]); swap(p[x[i]], p[y[i]]); P[c]=s1[i]; Q[c]=s1[S[i]]; c++; swap(S[i], S[S[i]]); } } for(int i=c; i<l; i++){ P[i]=0; Q[i]=0; } return l; }
#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...