Submission #727404

# Submission time Handle Problem Language Result Execution time Memory
727404 2023-04-20T15:14:49 Z vjudge1 Sorting (IOI15_sorting) C++11
100 / 100
366 ms 27520 KB
#include "sorting.h"

#include <bits/stdc++.h>
using namespace std;

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
        auto solve = [&](int lim) {
                vector<int> a(M), b(M);
                for (int i = 0; i < N; i++) a[i] = S[i];
                for (int i = 0; i < lim; i++) swap(a[X[i]], a[Y[i]]);
                for (int i = 0; i < N; i++) b[a[i]] = i;
                vector<pair<int, int>> changes;
                for (int i = 0; i < N; i++) {
                        if (a[i] != i) {
                                changes.emplace_back(i, a[i]);
                                int pos = b[i];
                                swap(b[a[i]], b[a[pos]]);
                                swap(a[i], a[pos]);
                        }
                }
                if (changes.size() > lim) return 0;
                for (int i = 0; i < N; i++) a[i] = S[i];
                for (int i = 0; i < N; i++) b[a[i]] = i;
                for (int i = 0; i < changes.size(); i++) {
                        swap(b[a[X[i]]], b[a[Y[i]]]);
                        swap(a[X[i]], a[Y[i]]);
                        P[i] = b[changes[i].first];
                        Q[i] = b[changes[i].second];
                        swap(b[a[P[i]]], b[a[Q[i]]]);
                        swap(a[P[i]], a[Q[i]]);
                }
                return 1;
        };
        int l = 0, r = M, res = -1;
        while (l <= r) {
                if (solve(l + r >> 1)) {
                        res = l + r >> 1;
                        r = (l + r >> 1) - 1;
                } else {
                        l = (l + r >> 1) + 1;
                }
        }
        for (int i = 0; i < M; i++) P[i] = Q[i] = 0;
        assert(solve(res));
        return res;
}

Compilation message

sorting.cpp: In lambda function:
sorting.cpp:21:36: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |                 if (changes.size() > lim) return 0;
      |                     ~~~~~~~~~~~~~~~^~~~~
sorting.cpp:24:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |                 for (int i = 0; i < changes.size(); i++) {
      |                                 ~~^~~~~~~~~~~~~~~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:36:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |                 if (solve(l + r >> 1)) {
      |                           ~~^~~
sorting.cpp:37:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |                         res = l + r >> 1;
      |                               ~~^~~
sorting.cpp:38:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |                         r = (l + r >> 1) - 1;
      |                              ~~^~~
sorting.cpp:40:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |                         l = (l + r >> 1) + 1;
      |                              ~~^~~
# 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 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 304 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 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 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 304 KB Output is correct
13 Correct 1 ms 212 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 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 2 ms 688 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 652 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 532 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 3 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 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 532 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 282 ms 24564 KB Output is correct
16 Correct 317 ms 25020 KB Output is correct
17 Correct 340 ms 26260 KB Output is correct
18 Correct 144 ms 22120 KB Output is correct
19 Correct 260 ms 25156 KB Output is correct
20 Correct 280 ms 25752 KB Output is correct
21 Correct 259 ms 25800 KB Output is correct
22 Correct 280 ms 21700 KB Output is correct
23 Correct 308 ms 27260 KB Output is correct
24 Correct 353 ms 27032 KB Output is correct
25 Correct 365 ms 26556 KB Output is correct
26 Correct 256 ms 25728 KB Output is correct
27 Correct 233 ms 25264 KB Output is correct
28 Correct 304 ms 26772 KB Output is correct
29 Correct 304 ms 26516 KB Output is correct
30 Correct 173 ms 24560 KB Output is correct
31 Correct 335 ms 27084 KB Output is correct
32 Correct 300 ms 26336 KB Output is correct
33 Correct 366 ms 26768 KB Output is correct
34 Correct 301 ms 26692 KB Output is correct
35 Correct 238 ms 24680 KB Output is correct
36 Correct 90 ms 23608 KB Output is correct
37 Correct 358 ms 27520 KB Output is correct
38 Correct 336 ms 26492 KB Output is correct
39 Correct 328 ms 26848 KB Output is correct