#include "sorting.h"
#include <iostream>
#include <algorithm>
using namespace std;
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
int A[N], pos[N];
for (int i = 0; i < N; ++i)
A[i] = i;
for (int i = M - 1; i >= 0; --i)
swap(A[X[i]], A[Y[i]]);
int r = 0;
for (int i = 0; i < M; ++i) {
bool f = 1;
for (int j = 1; j < N; ++j)
if (S[j - 1] > S[j])
f = 0;
if (f)
break;
swap(S[X[i]], S[Y[i]]);
swap(A[X[i]], A[Y[i]]);
f = 1;
for (int j = 1; j < N; ++j)
if (S[j - 1] > S[j])
f = 0;
if (f) {
r = i + 1;
Q[i] = P[i] = 0;
break;
}
for (int j = 0; j < N; ++j)
pos[A[j]] = j;
for (int j = 0; j < N; ++j) {
if (pos[S[j]] != j) {
Q[i] = j, P[i] = pos[S[j]];
break;
}
}
swap(S[Q[i]], S[P[i]]);
}
return r;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
52 ms |
372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
52 ms |
372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |