제출 #69035

#제출 시각아이디문제언어결과실행 시간메모리
69035theknife2001정렬하기 (IOI15_sorting)C++17
36 / 100
6 ms640 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; const int NN=555; int b[NN]; int n; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n=N; for(int i=0;i<n;i++) b[S[i]]=i; int ans=0; for(int i=0;i<n;i++) { if(S[i]!=i) break; if(i==n-1) return ans; } for(int i=0;i<n;i++) { if(S[i]!=i) break; if(i==n-1) return ans; } for(int j=0;j<M;j++) { b[S[X[j]]]=Y[j]; b[S[Y[j]]]=X[j]; swap(S[Y[j]],S[X[j]]); for(int i=0;i<n;i++) { if(S[i]!=i) break; if(i==n-1) { P[ans]=0; Q[ans]=0; ans++; return ans; } } for(int i=n-1;i>=0;i--) { if(S[i]!=i) { P[ans]=b[i]; Q[ans]=b[S[i]]; swap(b[i],b[S[i]]); swap(S[i],S[b[S[i]]]); ans++; break ; } } for(int i=0;i<n;i++) { if(S[i]!=i) break; if(i==n-1) return ans; } } return 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...