#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
vector< int > simul(M);
for(int i = 0; i < N; i++){
simul[i] = i;
}
for(int i = 0; i < M; i++){
swap(simul[X[i]], simul[Y[i]]);
}
vector< int > ends(N);
for(int i = 0; i < N; i++){
ends[simul[i]] = i;
}
for(int i = 0; i < N; i++){
simul[i] = i;
}
for(int i = 0; i < M; i++){
swap(simul[X[i]], simul[Y[i]]);
swap(S[X[i]], S[Y[i]]);
int index = -1;
int lookFor = -1;
bool verif = false;
for(int j = 0; j < N; j++){
if(S[j] != ends[simul[j]]){
if(index == -1){
index = j;
lookFor = ends[simul[j]];
}else if(lookFor == S[j]){
P[i] = index;
Q[i] = j;
verif = true;
//cout << "SWAP " << i << ' ' << "NUM " << index << ' ' << j << endl;
swap(S[index], S[j]);
break;
}
}
}
if(!verif){
P[i] = 0;
Q[i] = 0;
}
}
return M;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |