//#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 it[200001];
int n;
int xx[3*200001];
int yy[3*200001];
int pp[3*200001];
int qq[3*200001];
int cur[200001];//position in which it has to end up
int cur2[200001];//position in which number is currently ends in
//int cur3[2000001];//position which indes up in
bool check(int mid){
for(int i=0;i<n;i++){
cur[i]=it[i];
}
/*for(int i=0;i<n;i++){
cout<<cur[i]<<"<";
}
cout<<endl;
cout<<mid<<",,"<<endl;*/
for(int i=0;i<mid;i++){
swap(cur[xx[i]],cur[yy[i]]);
/*for(int ii=0;ii<n;ii++){
cout<<cur[ii]<<"/";
}*/
//cout<<endl;
//cout<<xx[i]<<"<<"<<yy[i]<<endl;
for(int ii=0;ii<n;ii++){
cur2[ii]=ii;
}
for(int j=i+1;j<mid;j++){
swap(cur2[xx[j]],cur2[yy[j]]);
}
int ind=-1;
for(int j=0;j<n;j++){
if(cur2[j]!=cur[j]){
ind=j;
break;
}
}
//cout<<ind<<":"<<endl;
if(ind==-1){
pp[i]=0;
qq[i]=0;
}
else{
int ind2=-1;
for(int j=0;j<n;j++){
if(cur2[j]==cur[ind]){
ind2=j;
break;
}
}
//cout<<ind<<",,,"<<ind2<<endl;
swap(cur[ind2],cur[ind]);
pp[i]=ind;
qq[i]=ind2;
}
/*for(int j=0;j<mid;j++){
}*/
}
for(int i=0;i<n;i++){
if(cur[i]!=i){
return false;
}
}
/* for(int i=0;i<n;i++){
cout<<cur[i]<<"<";
}
cout<<endl;*/
return true;
}
int findSwapPairs(int nn, int aa[], int m, int x[], int y[], int p[], int q[]){
n=nn;
for(int i=0;i<n;i++){
it[i]=aa[i];
//cout<<it[i]<<",";
}
//cout<<endl;
for(int i=0;i<m;i++){
xx[i]=x[i];
yy[i]=y[i];
}
int low=-1;
for(int j=19;j>=0;j--){
if(low+(1<<j)<=m){
if(check(low+(1<<j))==false){
low+=(1<<j);
}
}
}
low+=1;
//cout<<low<<":"<<endl;
check(low);
for(int i=0;i<low;i++){
p[i]=pp[i];
q[i]=qq[i];
}
return low;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
11 ms |
424 KB |
Output is correct |
11 |
Correct |
11 ms |
412 KB |
Output is correct |
12 |
Correct |
12 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
11 ms |
332 KB |
Output is correct |
4 |
Correct |
12 ms |
332 KB |
Output is correct |
5 |
Correct |
12 ms |
428 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
11 ms |
424 KB |
Output is correct |
11 |
Correct |
11 ms |
412 KB |
Output is correct |
12 |
Correct |
12 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
11 ms |
332 KB |
Output is correct |
16 |
Correct |
12 ms |
332 KB |
Output is correct |
17 |
Correct |
12 ms |
428 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
300 KB |
Output is correct |
21 |
Execution timed out |
1064 ms |
884 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
150 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
150 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |