# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
789922 | 2023-07-22T07:22:46 Z | Amylopectin | Sorting (IOI15_sorting) | C++14 | 130 ms | 22304 KB |
#include "sorting.h" #include <stdio.h> #include <vector> #include <algorithm> const int mxn = 1e6 + 10; // const int mxn = 110; int ctem[mxn] = {},u[mxn] = {},sta[mxn] = {},bac[mxn] = {},s[mxn] = {}; int findSwapPairs(int n, int ss[], int m, int x[], int y[], int p[], int q[]) { int i,j,cl=0,cr=n,mid,cn,cm,fn,fm,cou; for(i=0; i<n; i++) { s[i] = ss[i]; } while(cl < cr) { mid = (cl+cr) / 2; for(i=0; i<n; i++) { ctem[i] = i; u[i] = 0; } for(i=mid-1; i>=0; i--) { cn = ctem[x[i]]; ctem[x[i]] = ctem[y[i]]; ctem[y[i]] = cn; } for(i=0; i<n; i++) { sta[ctem[i]] = s[i]; } cou = 0; for(i=0; i<n; i++) { if(u[i] == 0) { cou ++; cn = sta[i]; u[i] = 1; while(cn != i) { u[cn] = 1; cn = sta[cn]; } } } if(n-cou <= mid) { cr = mid; } else { cl = mid+1; } } for(i=0; i<n; i++) { ctem[i] = i; u[i] = 0; } for(i=cl-1; i>=0; i--) { cn = ctem[x[i]]; ctem[x[i]] = ctem[y[i]]; ctem[y[i]] = cn; } for(i=0; i<n; i++) { sta[ctem[i]] = s[i]; bac[s[i]] = i; } cou = 0; fn = s[x[cou]]; s[x[cou]] = s[y[cou]]; s[y[cou]] = fn; bac[s[x[cou]]] = x[cou]; bac[s[y[cou]]] = y[cou]; for(i=0; i<n; i++) { if(u[i] == 0) { cn = sta[i]; u[i] = 1; fm = i; while(cn != i) { u[cn] = 1; p[cou] = bac[fm]; q[cou] = bac[cn]; cou++; fn = bac[fm]; bac[fm] = bac[cn]; bac[cn] = fn; fn = s[bac[fm]]; s[bac[fm]] = s[bac[cn]]; s[bac[cn]] = fn; fn = s[x[cou]]; s[x[cou]] = s[y[cou]]; s[y[cou]] = fn; bac[s[x[cou]]] = x[cou]; bac[s[y[cou]]] = y[cou]; fm = cn; cn = sta[cn]; } } } if(cou < cl) { for(i=cou; i<cl; i++) { p[i] = 0; q[i] = 0; } } return cl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 288 KB | Output is correct |
6 | Correct | 0 ms | 288 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 288 KB | Output is correct |
6 | Correct | 0 ms | 288 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 288 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 300 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 292 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 292 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 288 KB | Output is correct |
6 | Correct | 0 ms | 288 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 288 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 300 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 292 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 0 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 292 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 296 KB | Output is correct |
21 | Correct | 1 ms | 468 KB | Output is correct |
22 | Correct | 1 ms | 468 KB | Output is correct |
23 | Correct | 1 ms | 468 KB | Output is correct |
24 | Correct | 1 ms | 468 KB | Output is correct |
25 | Correct | 1 ms | 468 KB | Output is correct |
26 | Correct | 1 ms | 444 KB | Output is correct |
27 | Correct | 1 ms | 540 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 432 KB | Output is correct |
2 | Correct | 1 ms | 436 KB | Output is correct |
3 | Correct | 1 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 1 ms | 468 KB | Output is correct |
6 | Correct | 1 ms | 468 KB | Output is correct |
7 | Correct | 1 ms | 468 KB | Output is correct |
8 | Correct | 1 ms | 468 KB | Output is correct |
9 | Correct | 1 ms | 468 KB | Output is correct |
10 | Correct | 1 ms | 436 KB | Output is correct |
11 | Correct | 1 ms | 468 KB | Output is correct |
12 | Correct | 1 ms | 468 KB | Output is correct |
13 | Correct | 1 ms | 468 KB | Output is correct |
14 | Correct | 1 ms | 468 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 432 KB | Output is correct |
2 | Correct | 1 ms | 436 KB | Output is correct |
3 | Correct | 1 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 1 ms | 468 KB | Output is correct |
6 | Correct | 1 ms | 468 KB | Output is correct |
7 | Correct | 1 ms | 468 KB | Output is correct |
8 | Correct | 1 ms | 468 KB | Output is correct |
9 | Correct | 1 ms | 468 KB | Output is correct |
10 | Correct | 1 ms | 436 KB | Output is correct |
11 | Correct | 1 ms | 468 KB | Output is correct |
12 | Correct | 1 ms | 468 KB | Output is correct |
13 | Correct | 1 ms | 468 KB | Output is correct |
14 | Correct | 1 ms | 468 KB | Output is correct |
15 | Correct | 102 ms | 12240 KB | Output is correct |
16 | Correct | 109 ms | 20492 KB | Output is correct |
17 | Correct | 130 ms | 21516 KB | Output is correct |
18 | Correct | 52 ms | 17008 KB | Output is correct |
19 | Correct | 99 ms | 19844 KB | Output is correct |
20 | Correct | 107 ms | 20428 KB | Output is correct |
21 | Correct | 106 ms | 20512 KB | Output is correct |
22 | Correct | 102 ms | 16944 KB | Output is correct |
23 | Correct | 122 ms | 22304 KB | Output is correct |
24 | Correct | 130 ms | 21856 KB | Output is correct |
25 | Correct | 129 ms | 21732 KB | Output is correct |
26 | Correct | 103 ms | 20560 KB | Output is correct |
27 | Correct | 95 ms | 19788 KB | Output is correct |
28 | Correct | 120 ms | 21876 KB | Output is correct |
29 | Correct | 119 ms | 21272 KB | Output is correct |
30 | Correct | 72 ms | 19300 KB | Output is correct |
31 | Correct | 116 ms | 21708 KB | Output is correct |
32 | Correct | 116 ms | 21280 KB | Output is correct |
33 | Correct | 125 ms | 21904 KB | Output is correct |
34 | Correct | 117 ms | 21904 KB | Output is correct |
35 | Correct | 97 ms | 19660 KB | Output is correct |
36 | Correct | 47 ms | 18212 KB | Output is correct |
37 | Correct | 126 ms | 21964 KB | Output is correct |
38 | Correct | 118 ms | 21504 KB | Output is correct |
39 | Correct | 122 ms | 21084 KB | Output is correct |