//#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(aa[x[i]],aa[y[i]]);
int ind=-1;
p[i]=0;
q[i]=0;
for(int j=0;j<n;j++){
cur[j]=j;
}
for(int j=i+1;j<m;j++){
swap(cur[x[j]],cur[y[j]]);
}
for(int j=0;j<n;j++){
if(aa[j]!=cur[j]){
ind=j;
break;
}
}
if(ind==-1){
int st=1;
for(int j=0;j<n;j++){
if(aa[j]!=j){
st=0;
}
}
if(st==1){
return i+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]]);
int st=1;
for(int j=0;j<n;j++){
if(aa[j]!=j){
st=0;
}
}
if(st==1){
return i+1;
}
}
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++){
if(bb[i]!=i){
while(true){
continue;
}
}
}*/
/* 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 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
2 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 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
68 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
68 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |