# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
36912 | 2017-12-17T16:40:57 Z | moonrabbit2 | 정렬하기 (IOI15_sorting) | C++11 | 239 ms | 13304 KB |
#include "sorting.h" #include <bits/stdc++.h> #define N 200005 using namespace std; int a[N],pl[N]; int fp[N],fq[N]; bool visit[N]; int findSwapPairs(int n,int arr[],int mm,int x[],int y[],int p[],int q[]){ int s=1,e=n-1,ans=n-1; bool issort=true; for(int i=0;i<n;i++) if(arr[i]!=i) issort=false; if(issort) return 0; while(s<=e){ for(int i=0;i<n;i++) a[i]=arr[i],pl[i]=i,visit[i]=false; int m=(s+e)/2,res=0; for(int i=0;i<m;i++) swap(a[x[i]],a[y[i]]); for(int i=0;i<n;i++) pl[a[i]]=i; for(int i=0;i<n;i++){ if(visit[i]) continue; int curr=i,amt=1; visit[i]=true; while(pl[curr]!=i){ //un(curr,pl[curr]); curr=pl[curr]; visit[curr]=true; amt++; } res+=amt-1; } if(res<=m){ e=m-1; ans=m; } else s=m+1; } for(int i=0;i<n;i++) a[i]=arr[i]; int res=0,cp=0; for(int i=0;i<n;i++) pl[a[i]]=i; for(int i=0;i<ans;i++) swap(a[x[i]],a[y[i]]); for(int i=0;i<ans;i++){ while(cp<n&&cp==a[cp]) cp++; if(cp<n){ fp[i]=a[cp],fq[i]=a[a[cp]]; swap(a[cp],a[a[cp]]); } else{ fp[i]=fq[i]=1; } } for(int i=0;i<n;i++) a[i]=arr[i]; for(int i=0;i<ans;i++){ swap(pl[a[x[i]]],pl[a[y[i]]]); swap(a[x[i]],a[y[i]]); p[i]=pl[fp[i]],q[i]=pl[fq[i]]; swap(pl[fp[i]],pl[fq[i]]); swap(a[pl[fp[i]]],a[pl[fq[i]]]); } return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 512 KB | Output is correct |
3 | Correct | 2 ms | 300 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 512 KB | Output is correct |
3 | Correct | 2 ms | 300 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 3 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 3 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 256 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 512 KB | Output is correct |
3 | Correct | 2 ms | 300 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 3 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 3 ms | 384 KB | Output is correct |
13 | Correct | 3 ms | 256 KB | Output is correct |
14 | Correct | 3 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 3 ms | 384 KB | Output is correct |
17 | Correct | 3 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 3 ms | 256 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 2 ms | 512 KB | Output is correct |
22 | Correct | 3 ms | 512 KB | Output is correct |
23 | Correct | 3 ms | 512 KB | Output is correct |
24 | Correct | 3 ms | 512 KB | Output is correct |
25 | Correct | 3 ms | 512 KB | Output is correct |
26 | Correct | 2 ms | 512 KB | Output is correct |
27 | Correct | 3 ms | 512 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 512 KB | Output is correct |
2 | Correct | 3 ms | 512 KB | Output is correct |
3 | Correct | 3 ms | 512 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 3 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 484 KB | Output is correct |
8 | Correct | 3 ms | 512 KB | Output is correct |
9 | Correct | 4 ms | 512 KB | Output is correct |
10 | Correct | 3 ms | 512 KB | Output is correct |
11 | Correct | 3 ms | 512 KB | Output is correct |
12 | Correct | 3 ms | 512 KB | Output is correct |
13 | Correct | 3 ms | 512 KB | Output is correct |
14 | Correct | 3 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 512 KB | Output is correct |
2 | Correct | 3 ms | 512 KB | Output is correct |
3 | Correct | 3 ms | 512 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 3 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 484 KB | Output is correct |
8 | Correct | 3 ms | 512 KB | Output is correct |
9 | Correct | 4 ms | 512 KB | Output is correct |
10 | Correct | 3 ms | 512 KB | Output is correct |
11 | Correct | 3 ms | 512 KB | Output is correct |
12 | Correct | 3 ms | 512 KB | Output is correct |
13 | Correct | 3 ms | 512 KB | Output is correct |
14 | Correct | 3 ms | 384 KB | Output is correct |
15 | Correct | 156 ms | 11152 KB | Output is correct |
16 | Correct | 193 ms | 11272 KB | Output is correct |
17 | Correct | 204 ms | 12380 KB | Output is correct |
18 | Correct | 38 ms | 5496 KB | Output is correct |
19 | Correct | 178 ms | 9976 KB | Output is correct |
20 | Correct | 184 ms | 10476 KB | Output is correct |
21 | Correct | 194 ms | 10616 KB | Output is correct |
22 | Correct | 170 ms | 12024 KB | Output is correct |
23 | Correct | 207 ms | 12280 KB | Output is correct |
24 | Correct | 239 ms | 12332 KB | Output is correct |
25 | Correct | 204 ms | 12508 KB | Output is correct |
26 | Correct | 191 ms | 10460 KB | Output is correct |
27 | Correct | 170 ms | 9724 KB | Output is correct |
28 | Correct | 195 ms | 11896 KB | Output is correct |
29 | Correct | 215 ms | 11900 KB | Output is correct |
30 | Correct | 119 ms | 8952 KB | Output is correct |
31 | Correct | 210 ms | 12224 KB | Output is correct |
32 | Correct | 186 ms | 11896 KB | Output is correct |
33 | Correct | 233 ms | 12536 KB | Output is correct |
34 | Correct | 200 ms | 12332 KB | Output is correct |
35 | Correct | 159 ms | 9948 KB | Output is correct |
36 | Correct | 49 ms | 7548 KB | Output is correct |
37 | Correct | 210 ms | 13304 KB | Output is correct |
38 | Correct | 215 ms | 12536 KB | Output is correct |
39 | Correct | 237 ms | 12888 KB | Output is correct |