Submission #752800

# Submission time Handle Problem Language Result Execution time Memory
752800 2023-06-03T21:30:58 Z jampm Sorting (IOI15_sorting) C++17
0 / 100
1 ms 340 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
const int LOGN = 30;

int count_cycles(vector<int> & V, int N = 0) {
  N = (int)V.size(); int ans = 0;
  vector<bool> vis(N, false);
  for (int i = 0; i < N; i++) {
    if (vis[i]) continue;
    ans++;
    for (int j = V[i]; i != j; j = V[j]) vis[j] = true;
  }
  return ans;
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
  int ans = 0;
  for (int k = LOGN; k >= 0; k--) {
    if (ans + (1<<k) > M) continue;
    vector<int> V(N);
    for (int i = 0; i < N; i++) V[i] = S[i];
    for (int i = 0; i < ans + (1<<k); i++) {
      swap(V[X[i]], V[Y[i]]);
    }
    if (count_cycles(V) + ans + (1<<k) < N) ans += (1<<k);
  }
  ans++;
  vector<int> V(N);
  for (int i = 0; i < N; i++) V[i] = S[i];
  for (int i = 0; i < ans; i++) {
    swap(V[X[i]], V[Y[i]]);
  }
  vector<bool> vis(N, false);
  //tengo que ver bien el orden de los swaps 
  vector<pair<int, int>> Ans(N - count_cycles(V));
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (vis[i]) continue;
    for (int j = V[i]; i != j; j = V[j]) {
      vis[j] = true; Ans[cnt++] = {j, V[j]};
    }
  }
  random_shuffle(Ans.begin(), Ans.end());
  for (int i = 0; i < Ans.size(); i++) {
    P[i] = Ans[i].first;
    Q[i] = Ans[i].second;
  }
  return ans;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int i = 0; i < Ans.size(); i++) {
      |                   ~~^~~~~~~~~~~~
# 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 0 ms 212 KB Output is correct
4 Correct 1 ms 304 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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 304 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 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 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 0 ms 212 KB Output is correct
4 Correct 1 ms 304 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 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -