제출 #1018546

#제출 시각아이디문제언어결과실행 시간메모리
1018546huutuanSorting (IOI15_sorting)C++14
54 / 100
5 ms728 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; int a[200010], pos[200010]; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { iota(a, a+N, 0); for (int i=0; i<N; ++i) pos[S[i]]=i; for (int i=M-1; i>=0; --i) swap(a[X[i]], a[Y[i]]); if (is_sorted(S, S+N)) return 0; for (int i=0; i<M; ++i){ P[i]=Q[i]=0; swap(a[X[i]], a[Y[i]]); if (is_sorted(S, S+N)) return i+1; swap(S[X[i]], S[Y[i]]); pos[S[X[i]]]=X[i]; pos[S[Y[i]]]=Y[i]; for (int j=0; j<N; ++j) if (a[j]!=S[j]){ int k=pos[a[j]]; P[i]=j, Q[i]=k; break; } swap(S[P[i]], S[Q[i]]); pos[S[P[i]]]=P[i]; pos[S[Q[i]]]=Q[i]; if (is_sorted(S, S+N)) return i+1; } return M; }
#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...