제출 #385043

#제출 시각아이디문제언어결과실행 시간메모리
385043qpwoeirutSorting (IOI15_sorting)C++17
0 / 100
2 ms620 KiB
#include "sorting.h" #include <algorithm> #include <cassert> #include <iostream> using namespace std; #define val first #define idx second typedef pair<int,int> pii; const int MN = 200005; pii A[MN]; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int K = 0; auto record_swaps = [&](pii& a, pii& b) { if (a.val > b.val) { P[K] = a.idx; Q[K] = b.idx; swap(a.idx, b.idx); ++K; } return a.val < b.val; }; for (int i=0; i<N; ++i) { A[i] = pii(S[i], i); } if (X[0] == 0 && Y[0] == 0) { sort(A, A+N, record_swaps); } else if (X[0] == 0 && Y[0] == 1) { sort(A+2, A+N, record_swaps); if ((K & 1) == 0) swap(A[0], A[1]); while (A[0].val + A[1].val > 1) { if (A[0] < A[1]) { P[K] = 1; swap(A[1], A[2]); } else { P[K] = 0; swap(A[0], A[2]); } Q[K] = 2; ++K; swap(A[0], A[1]); for (int i=2; i+1<N; ++i) { if (!record_swaps(A[i], A[i+1])) { swap(A[i], A[i+1]); swap(A[0], A[1]); } else break; } } } else assert(0); assert(K <= M); return K; }
#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...