#include "sorting.h"
#include <random>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
mt19937 mt(2009190008);
int rand_rng(int l, int r) {
uniform_int_distribution<int> p(l, r - 1);
return p(mt);
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
fill(P, P + M, 0);
fill(Q, Q + M, 0);
for(int i = 0; i < M; ++i) {
if(is_sorted(S, S + N)) {
return i;
}
swap(S[X[i]], S[Y[i]]);
if(is_sorted(S, S + N)) {
return i + 1;
}
vector<int> col(N, -1);
for(int j = 0; j < N; ++j) {
if(col[j] != -1) continue;
int pos = j;
while(col[pos] == -1) {
col[pos] = j;
pos = S[pos];
}
}
do {
P[i] = rand_rng(0, N);
Q[i] = rand_rng(0, N);
} while(P[i] == Q[i] || col[P[i]] != col[Q[i]]);
}
if(is_sorted(S, S + N)) {
return M;
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
48 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
48 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |