Submission #427234

# Submission time Handle Problem Language Result Execution time Memory
427234 2021-06-14T13:34:28 Z ollel Sorting (IOI15_sorting) C++17
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back
#define lso(x) x&(-x)

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;

int N;
bool sorted(int s[]) {
  rep(i,0,N) if (s[i] != i) return false;
  return true;
}

int findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
  N = n;
  int r = 0;

  if (sorted(S)) return 0;

  swap(S[X[r]], S[Y[r]]);
  rep(i,0,n) if (S[i] == 0) {
    P[r] = i; Q[r] = 0;
    swap(S[i], S[0]);
    r++;
  }
  swap(S[X[r]], S[Y[r]]);
  rep(i,0,n) if (S[i] == 1) {
    P[r] = i; Q[r] = 0;
    swap(S[i], S[0]);
    r++;
  }

  rep(i, 2, n) {
    while (S[i] != i) {
      swap(S[X[r]], S[Y[r]]);
      P[r] = i;
      Q[r] = S[i];
      swap(S[i], S[S[i]]);
      r++;
    }
  }

  if (sorted(S)) return r;
  P[r] = Q[r] = 0;
  return r + 1;
}

// int main() {
//   int n = 5;
//   int S[] = {4, 3, 1, 0, 2};
//   int M;
//   int X[25] = {1, 2, 3, 4, 0}, Y[25] = {4, 0, 1, 2, 0}, P[25], Q[25];
//   cout << findSwapPairs(n, S, M, X, Y, P, Q) << endl;
//   rep (i, 0, 25) cout << P[i] << " " << Q[i] << endl;
// }

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:19:39: warning: unused parameter 'M' [-Wunused-parameter]
   19 | int findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -