//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
//#define endl '\n'
#include "sorting.h"
int cur[200001];
int findSwapPairs(int n, int aa[], int m, int x[], int y[], int p[], int q[]){
int stt=1;
for(int i=0;i<n;i++){
cur[i]=i;
if(aa[i]!=i){
stt=0;
}
}
if(stt==1){
return 0;
}
for(int i=m-1;i>=0;i--){
swap(cur[x[i]],cur[y[i]]);
}
vector<int> bb;
for(int i=0;i<n;i++){
bb.pb(aa[i]);
}
for(int i=0;i<m;i++){
swap(cur[x[i]],cur[y[i]]);
swap(aa[x[i]],aa[y[i]]);
int ind=-1;
p[i]=0;
q[i]=0;
for(int j=0;j<n;j++){
if(aa[j]!=cur[j]){
ind=j;
break;
}
}
int st=1;
for(int j=0;j<n;j++){
if(aa[j]!=j){
st=0;
}
}
if(st==1){
return i+1;
}
if(ind==-1){
continue;
}
int ind2=-1;
for(int j=0;j<n;j++){
if(cur[j]==aa[ind]){
ind2=j;
}
}
p[i]=ind;
q[i]=ind2;
swap(aa[p[i]],aa[q[i]]);
}
for(int i=0;i<m;i++){
swap(bb[x[i]],bb[y[i]]);
swap(bb[p[i]],bb[q[i]]);
}
/* for(int i=0;i<n;i++){
cout<<bb[i]<<":";
}
cout<<endl;
*/
return m;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |