Submission #730859

# Submission time Handle Problem Language Result Execution time Memory
730859 2023-04-26T14:32:47 Z josanneo22 Sorting (IOI15_sorting) C++17
100 / 100
348 ms 22588 KB
#include "sorting.h"
#include <algorithm>
using namespace std;
 
int *s, *x, *y, *p, *q, n;
int obj[200005], cur[200005];
int orev[200005], crev[200005];
 
bool trial(int t){
    for(int i=0; i<n; i++){
        obj[i] = i;
    }
    for(int i=t-1; i>=0; i--){
        swap(obj[x[i]], obj[y[i]]);
    }
    for(int i=0; i<n; i++){
        orev[obj[i]] = i;
        cur[i] = s[i];
        crev[cur[i]] = i;
    }
    int pt = 0;
    for(int i=0; i<t; i++){
        swap(obj[x[i]], obj[y[i]]);
        swap(cur[x[i]], cur[y[i]]);
        crev[cur[x[i]]] = x[i];
        orev[obj[x[i]]] = x[i];
        crev[cur[y[i]]] = y[i];
        orev[obj[y[i]]] = y[i];
        while(pt < n && crev[pt] == orev[pt]) pt++;
        if(pt == n){
            p[i] = q[i] = 0;
            continue;
        }
        int p1 = crev[pt];
        int p2 = orev[pt];
        p[i] = p1;
        q[i] = p2;
        swap(cur[p1], cur[p2]);
        crev[cur[p1]] = p1;
        crev[cur[p2]] = p2;
    }
    while(pt < n && crev[pt] == orev[pt]) pt++;
    return (pt == n);
}
 
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    n = N, s = S, x = X, y = Y, p = P, q = Q;
    int s = 0, e = M;
    while(s != e){
        int m = (s+e)/2;
        if(trial(m)) e = m;
        else s = m+1;
    }
    trial(s);
    return s;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:48:9: warning: declaration of 's' shadows a global declaration [-Wshadow]
   48 |     int s = 0, e = M;
      |         ^
sorting.cpp:5:6: note: shadowed declaration is here
    5 | int *s, *x, *y, *p, *q, n;
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 296 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 2 ms 560 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 544 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 436 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 500 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 436 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 500 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 250 ms 19936 KB Output is correct
16 Correct 290 ms 20512 KB Output is correct
17 Correct 332 ms 21540 KB Output is correct
18 Correct 100 ms 18508 KB Output is correct
19 Correct 234 ms 20780 KB Output is correct
20 Correct 252 ms 21304 KB Output is correct
21 Correct 248 ms 21348 KB Output is correct
22 Correct 230 ms 16904 KB Output is correct
23 Correct 271 ms 22396 KB Output is correct
24 Correct 335 ms 22080 KB Output is correct
25 Correct 321 ms 21684 KB Output is correct
26 Correct 227 ms 21400 KB Output is correct
27 Correct 203 ms 20712 KB Output is correct
28 Correct 308 ms 21908 KB Output is correct
29 Correct 309 ms 21580 KB Output is correct
30 Correct 195 ms 20432 KB Output is correct
31 Correct 309 ms 21968 KB Output is correct
32 Correct 257 ms 21484 KB Output is correct
33 Correct 344 ms 22044 KB Output is correct
34 Correct 296 ms 21876 KB Output is correct
35 Correct 232 ms 20424 KB Output is correct
36 Correct 81 ms 19764 KB Output is correct
37 Correct 348 ms 22588 KB Output is correct
38 Correct 346 ms 21676 KB Output is correct
39 Correct 330 ms 21816 KB Output is correct