#include "sorting.h"
#include <bits/stdc++.h>
#define uwu return 0;
using namespace std;
const int SIZE = 2e5 + 5;
int s[SIZE], tar[SIZE], x[SIZE], y[SIZE], p[SIZE], q[SIZE], pos_of_val[SIZE];
void build(int M){
for(int i = M - 1; i >= 0; i--){
swap(tar[x[i]], tar[y[i]]);
}
return;
}
int get_sequence(int N, int M){
for(int i = 0; i < M; i++){
swap(s[x[i]], s[y[i]]);
for(int j = 0; j < N; j++){
pos_of_val[s[j]] = j;
}
swap(tar[x[i]], tar[y[i]]);
bool st = 0;
for(int j = 0; j < N; j++){
if(s[j] != tar[j]){
st = 1;
swap(s[j], s[pos_of_val[tar[j]]]);
p[i] = j;
q[i] = pos_of_val[tar[j]];
break;
}
}
if(!st)
return i + 1;
}
return M;
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
for(int i = 0; i < N; i++){
tar[i] = i;
s[i] = S[i];
}
for(int i = 0; i < M; i++){
x[i] = X[i];
y[i] = Y[i];
}
for(int i = 0; i < M; i++){
p[i] = 0;
q[i] = 0;
}
int k = get_sequence(N, M);
for(int i = 0; i < k; i++){
P[i] = p[i];
Q[i] = q[i];
}
return k;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
508 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
508 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
508 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |