# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
426099 |
2021-06-13T13:59:01 Z |
_fractal |
Sorting (IOI15_sorting) |
C++14 |
|
1000 ms |
19008 KB |
#include "sorting.h"
#include <iostream>
#include <algorithm>
using namespace std;
int findSwapPairs(int N, int SS[], int M, int X[], int Y[], int P[], int Q[]) {
int A[N], pos[N], L[M], R[M], ret = (1<<30), S[N];
int tl = 0, tr = M - 1;
while (tl <= tr) {
int m = tl + tr >> 1;
for (int i = 0; i < N; ++i)
A[i] = i, S[i] = SS[i];
for (int i = m; i >= 0; --i)
swap(A[X[i]], A[Y[i]]);
int r = -1;
for (int i = 0; i <= m; ++i) {
P[i] = Q[i] = 0;
bool f = 1;
for (int j = 1; j < N; ++j)
if (S[j - 1] > S[j])
f = 0;
if (f) {
r = i;
break;
}
swap(S[X[i]], S[Y[i]]);
swap(A[X[i]], A[Y[i]]);
f = 1;
for (int j = 1; j < N; ++j)
if (S[j - 1] > S[j])
f = 0;
if (f) {
r = i + 1;
break;
}
for (int j = 0; j < N; ++j)
pos[A[j]] = j;
for (int j = 0; j < N; ++j) {
if (pos[S[j]] != j) {
Q[i] = j, P[i] = pos[S[j]];
break;
}
}
swap(S[Q[i]], S[P[i]]);
}
bool f = 1;
for (int i = 1; i < N; ++i)
if (S[i - 1] > S[i])
f = 0;
if (!f) {
tl = m + 1;
continue;
}
tr = m - 1;
if (r == -1) r = m + 1;
if (ret >= r) {
ret = r;
for (int i = 0; i < r; ++i)
L[i] = Q[i], R[i] = P[i];
}
}
for (int i = 0; i < ret; ++i)
Q[i] = L[i], P[i]= R[i];
return ret;
}
Compilation message
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:11:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
11 | int m = tl + tr >> 1;
| ~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 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 |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 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 |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
47 ms |
668 KB |
Output is correct |
22 |
Correct |
47 ms |
588 KB |
Output is correct |
23 |
Correct |
49 ms |
700 KB |
Output is correct |
24 |
Correct |
44 ms |
672 KB |
Output is correct |
25 |
Correct |
49 ms |
760 KB |
Output is correct |
26 |
Correct |
46 ms |
588 KB |
Output is correct |
27 |
Correct |
48 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
412 KB |
Output is correct |
2 |
Correct |
209 ms |
476 KB |
Output is correct |
3 |
Correct |
213 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
64 ms |
496 KB |
Output is correct |
6 |
Correct |
84 ms |
488 KB |
Output is correct |
7 |
Correct |
149 ms |
500 KB |
Output is correct |
8 |
Correct |
211 ms |
484 KB |
Output is correct |
9 |
Correct |
210 ms |
488 KB |
Output is correct |
10 |
Correct |
226 ms |
480 KB |
Output is correct |
11 |
Correct |
223 ms |
488 KB |
Output is correct |
12 |
Correct |
148 ms |
460 KB |
Output is correct |
13 |
Correct |
228 ms |
480 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
412 KB |
Output is correct |
2 |
Correct |
209 ms |
476 KB |
Output is correct |
3 |
Correct |
213 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
64 ms |
496 KB |
Output is correct |
6 |
Correct |
84 ms |
488 KB |
Output is correct |
7 |
Correct |
149 ms |
500 KB |
Output is correct |
8 |
Correct |
211 ms |
484 KB |
Output is correct |
9 |
Correct |
210 ms |
488 KB |
Output is correct |
10 |
Correct |
226 ms |
480 KB |
Output is correct |
11 |
Correct |
223 ms |
488 KB |
Output is correct |
12 |
Correct |
148 ms |
460 KB |
Output is correct |
13 |
Correct |
228 ms |
480 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Execution timed out |
1087 ms |
19008 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |