이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |