#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
int n, m;
int s[MAXN], pos[MAXN];
int cnt[MAXN];
void do_swap(int x, int y) {
int p = s[x], q = s[y];
swap(pos[p], pos[q]);
swap(s[x], s[y]);
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
n = N;
m = M;
for (int i = 0; i < n; ++i) {
s[i] = S[i];
pos[s[i]] = i;
}
for (int i = 0; i < m; ++i) {
++cnt[X[i]];
++cnt[Y[i]];
}
for (int i = 0; i < m; ++i) {
do_swap(X[i], Y[i]);
--cnt[X[i]];
--cnt[Y[i]];
bool found = false;
for (int j = 0; j < n; ++j) {
if (pos[j] != j && cnt[j] == 0) {
found = true;
P[i] = j; Q[i] = pos[j];
do_swap(j, pos[j]);
break;
}
}
if (!found) P[i] = Q[i] = 0, do_swap(0, 0);
}
for (int i = 0; i < n; ++i) assert(s[i] == i);
return m;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
18 ms |
640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
18 ms |
640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |