Submission #426939

# Submission time Handle Problem Language Result Execution time Memory
426939 2021-06-14T11:03:17 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;

#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 findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
  if (n == 1) return 0;
  else if (n == 2) {
    if (S[0] == 0) return 0;
    P[0] = Q[0] = 0;
    return 1;
  }
  int r = 0, s = 0;
  rep(i,0,n) if (S[i] == i) s++;
  if (s == n) return 0;

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

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

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

  if (S[0] != 0) {
    swap(S[0], S[1]);
    P[r] = Q[r] = 0;
    r++;
  }

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

Compilation message

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