Submission #727394

# Submission time Handle Problem Language Result Execution time Memory
727394 2023-04-20T14:57:19 Z vjudge1 Sorting (IOI15_sorting) C++11
0 / 100
2 ms 468 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];
                }
                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:34:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |                 if (solve(l + r >> 1)) {
      |                           ~~^~~
sorting.cpp:35:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |                         res = l + r >> 1;
      |                               ~~^~~
sorting.cpp:36:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |                         r = (l + r >> 1) - 1;
      |                              ~~^~~
sorting.cpp:38:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |                         l = (l + r >> 1) + 1;
      |                              ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 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 296 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 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 296 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 300 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 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 296 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -