# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1090966 |
2024-09-19T09:06:42 Z |
owoovo |
Sorting (IOI15_sorting) |
C++17 |
|
207 ms |
15952 KB |
#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;
int tar[1000010],tarp[1000010],n,x[1000010],y[1000010],s[1000010];
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
n=N;
for(int i=0;i<M;i++){
x[i+1]=X[i];
y[i+1]=Y[i];
}
int l=0,r=M;
while(l!=r){
int m=(l+r)>>1,ok=1;
//cout<<l<<" "<<r<<" "<<m<<"\n";
for(int i=0;i<N;i++){
tar[i]=i;
s[i]=S[i];
}
for(int i=m;i>0;i--){
swap(tar[x[i]],tar[y[i]]);
}
for(int i=0;i<N;i++){
tarp[tar[i]]=i;
}
int ans=0;
for(int i=0;i<N;i++){
if(s[i]==tar[i])continue;
int ori=i;
while(tarp[s[ori]]!=ori){
P[ans]=tarp[s[ori]];
Q[ans]=ori;
swap(s[tarp[s[ori]]],s[ori]);
ans++;
}
}
if(ans>m){
l=m+1;
}else{
r=m;
}
}
int m=l;
for(int i=0;i<N;i++){
tar[i]=i;
s[i]=S[i];
}
for(int i=m;i>0;i--){
swap(tar[x[i]],tar[y[i]]);
}
for(int i=0;i<N;i++){
tarp[tar[i]]=i;
}
if(m!=0){
swap(tar[x[1]],tar[y[1]]);
swap(s[x[1]],s[y[1]]);
tarp[tar[x[1]]]=x[1];
tarp[tar[y[1]]]=y[1];
}
int ans=0;
for(int i=0;i<N;i++){
//cout<<s[i]<<" "<<tar[i]<<"\n";
if(s[i]==tar[i])continue;
int ori=i;
while(ori!=tarp[s[ori]]){
//cout<<now<<" "<<ori<<"\n";
P[ans]=tarp[s[ori]];
Q[ans]=ori;
swap(s[tarp[s[ori]]],s[ori]);
ans++;
if(ans>=m)break;
swap(tar[x[ans+1]],tar[y[ans+1]]);
swap(s[x[ans+1]],s[y[ans+1]]);
tarp[tar[x[ans+1]]]=x[ans+1];
tarp[tar[y[ans+1]]]=y[ans+1];
}
if(ans>=m)break;
}
for(int i=0;i<N;i++){
if(s[i]!=tar[i]){
cout<<"?\n";
}
}
for(int i=ans;i<m;i++)Q[i]=0,P[i]=0;
return l;
}
Compilation message
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:14:18: warning: unused variable 'ok' [-Wunused-variable]
14 | int m=(l+r)>>1,ok=1;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
428 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
428 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
716 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
620 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
620 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
175 ms |
14420 KB |
Output is correct |
16 |
Correct |
188 ms |
14740 KB |
Output is correct |
17 |
Correct |
200 ms |
15364 KB |
Output is correct |
18 |
Correct |
57 ms |
13136 KB |
Output is correct |
19 |
Correct |
124 ms |
15188 KB |
Output is correct |
20 |
Correct |
134 ms |
15484 KB |
Output is correct |
21 |
Correct |
132 ms |
15496 KB |
Output is correct |
22 |
Correct |
170 ms |
15636 KB |
Output is correct |
23 |
Correct |
194 ms |
15952 KB |
Output is correct |
24 |
Correct |
207 ms |
15700 KB |
Output is correct |
25 |
Correct |
207 ms |
15440 KB |
Output is correct |
26 |
Incorrect |
137 ms |
14932 KB |
Expected integer, but "?" found |
27 |
Halted |
0 ms |
0 KB |
- |