# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
452113 |
2021-08-03T19:34:45 Z |
JovanB |
Sorting (IOI15_sorting) |
C++17 |
|
402 ms |
31964 KB |
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
int niz[200005];
int x[600005], y[600005];
int p[600005], q[600005];
int n, m;
int prvo[200005];
int gde[200005];
int who[200005];
int tren[200005];
int trenwho[200005];
bool check(int k){
for(int i=0; i<n; i++){
gde[niz[i]] = i;
who[i] = niz[i];
tren[niz[i]] = i;
trenwho[i] = niz[i];
}
for(int i=0; i<k; i++){
swap(who[x[i]], who[y[i]]);
swap(gde[who[x[i]]], gde[who[y[i]]]);
}
for(int i=0; i<m; i++) p[i] = q[i] = 0;
int g = 0;
for(int i=0; i<n; i++){
if(gde[i] != i){
swap(trenwho[x[g]], trenwho[y[g]]);
swap(tren[trenwho[x[g]]], tren[trenwho[y[g]]]);
int u = who[i];
p[g] = tren[i];
q[g] = tren[u];
g++;
swap(trenwho[tren[i]], trenwho[tren[u]]);
swap(tren[i], tren[u]);
swap(who[gde[i]], who[gde[u]]);
swap(gde[i], gde[u]);
}
}
return g <= k;
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
n = N, m = M;
for(int i=0; i<n; i++){
niz[i] = S[i];
}
for(int i=0; i<m; i++){
x[i] = X[i];
y[i] = Y[i];
}
int l = 0, r = m, res = m;
while(l <= r){
int mid = (l+r)/2;
if(check(mid)){
res = mid;
r = mid-1;
}
else l = mid+1;
}
check(res);
for(int i=0; i<res; i++){
P[i] = p[i];
Q[i] = q[i];
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
436 KB |
Output is correct |
12 |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
436 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 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 |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
716 KB |
Output is correct |
22 |
Correct |
2 ms |
716 KB |
Output is correct |
23 |
Correct |
2 ms |
716 KB |
Output is correct |
24 |
Correct |
2 ms |
716 KB |
Output is correct |
25 |
Correct |
2 ms |
844 KB |
Output is correct |
26 |
Correct |
2 ms |
712 KB |
Output is correct |
27 |
Correct |
2 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
3 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
564 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
568 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
3 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
564 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
568 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
572 KB |
Output is correct |
15 |
Correct |
263 ms |
28324 KB |
Output is correct |
16 |
Correct |
326 ms |
28868 KB |
Output is correct |
17 |
Correct |
400 ms |
30448 KB |
Output is correct |
18 |
Correct |
111 ms |
25748 KB |
Output is correct |
19 |
Correct |
245 ms |
29096 KB |
Output is correct |
20 |
Correct |
262 ms |
29896 KB |
Output is correct |
21 |
Correct |
263 ms |
29960 KB |
Output is correct |
22 |
Correct |
251 ms |
25924 KB |
Output is correct |
23 |
Correct |
280 ms |
31684 KB |
Output is correct |
24 |
Correct |
402 ms |
31172 KB |
Output is correct |
25 |
Correct |
401 ms |
30712 KB |
Output is correct |
26 |
Correct |
272 ms |
29952 KB |
Output is correct |
27 |
Correct |
234 ms |
29064 KB |
Output is correct |
28 |
Correct |
363 ms |
30944 KB |
Output is correct |
29 |
Correct |
354 ms |
30448 KB |
Output is correct |
30 |
Correct |
193 ms |
28612 KB |
Output is correct |
31 |
Correct |
368 ms |
31064 KB |
Output is correct |
32 |
Correct |
274 ms |
30484 KB |
Output is correct |
33 |
Correct |
402 ms |
31120 KB |
Output is correct |
34 |
Correct |
322 ms |
31080 KB |
Output is correct |
35 |
Correct |
246 ms |
28684 KB |
Output is correct |
36 |
Correct |
82 ms |
27464 KB |
Output is correct |
37 |
Correct |
391 ms |
31964 KB |
Output is correct |
38 |
Correct |
373 ms |
30768 KB |
Output is correct |
39 |
Correct |
358 ms |
30912 KB |
Output is correct |