#ifdef ONLINE_JUDGE
#include "sorting.h"
#endif
#include "bits/stdc++.h"
using namespace std;
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]);
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
bool sorted =1 ;
for(int i=1; i<N; i++) {
sorted &= (S[i] >= S[i-1]);
}
if(sorted) return 0;
int T[N];
for(int i=0; i<N; i++) T[i] = S[i];
sort(T, T + N);
for(int i=0; i<M; i++) {
P[i] = 0, Q[i] = 0;
if(X[i] > Y[i]) swap(X[i], Y[i]);
if(S[X[i]] != T[X[i]] && S[Y[i]] != T[Y[i]]) {
swap(S[X[i]], S[Y[i]]);
for(int j=0; j<N; j++) {
if(S[j] != T[j]) {
for(int k=0; k<N; k++) {
if(S[k] == T[j] && S[k] != T[k]) {
P[i] = j, Q[i] = k;
swap(S[j], S[k]);
break;
}
}
break;
}
}
}
else {
swap(S[X[i]], S[Y[i]]);
bool done = 0;
for(int j=0; j<N; j++) {
if(j == X[i] || j == Y[i]) continue;
if(S[j] != T[j]) {
for(int k=0; k<N; k++) {
if(S[k] == T[j] && S[k] != T[k]) {
P[i] = j, Q[i] = k;
done = 1;
swap(S[j], S[k]);
break;
}
}
break;
}
}
if(!done) {
for(int j=0; j<N; j++) {
if(S[j] != T[j]) {
for(int k=0; k<N; k++) {
if(S[k] == T[j] && S[k] != T[k]) {
P[i] = j, Q[i] = k;
done = 1;
swap(S[j], S[k]);
break;
}
}
break;
}
}
}
}
}
return M;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
320 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |