Submission #752779

# Submission time Handle Problem Language Result Execution time Memory
752779 2023-06-03T20:51:50 Z jampm Sorting (IOI15_sorting) C++17
Compilation error
0 ms 0 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 = ssize(V); 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; auto &e : V) e = 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; auto &e : V) e = S[i++];
  for (int i = 0; i < ans; i++) {
    swap(V[X[i]], V[Y[i]]);
  }
  vector<bool> vis(N, false);
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (vis[i]) continue;
    P[cnt] = i, Q[cnt] = vis[i]; cnt++;
    for (int j = V[i]; i != j; j = V[j]) {
      P[cnt] = j, Q[cnt] = vis[j]; cnt++;
    }
  }
  return ans;
}

Compilation message

sorting.cpp: In function 'int count_cycles(std::vector<int>&, int)':
sorting.cpp:7:7: error: 'ssize' was not declared in this scope; did you mean 'dysize'?
    7 |   N = ssize(V); int ans = 0;
      |       ^~~~~
      |       dysize
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:22:21: warning: range-based 'for' loops with initializer only available with '-std=c++2a' or '-std=gnu++2a'
   22 |     for (int i = 0; auto &e : V) e = S[i++];
      |                     ^~~~
sorting.cpp:30:19: warning: range-based 'for' loops with initializer only available with '-std=c++2a' or '-std=gnu++2a'
   30 |   for (int i = 0; auto &e : V) e = S[i++];
      |                   ^~~~