Submission #427206

# Submission time Handle Problem Language Result Execution time Memory
427206 2021-06-14T13:22:40 Z ollel Sorting (IOI15_sorting) C++17
0 / 100
6 ms 844 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;

  while (!sorted(S)) {
    swap(S[X[r]], S[Y[r]]);
    if (sorted(S)) {P[r] = Q[r] = 0; return r + 1;}

    bool f = false;
    for (int mx = 4; mx >= 1; mx--) {
      rep(i,0,n) {
        rep(j, 1, mx) {
          if (S[i] != X[r + i] && S[i] != Y[r + i]) {
            cout << i << " " << S[i] << ", here\n";
            P[r] = i;
            Q[r] = S[i];
            swap(S[i], S[S[i]]);
            f = true;
            break;
          }
          if (f) break;
        }
        if (f) break;
      }
      if (f) break;
    }
    if (!f) P[r] = Q[r] = 0;
    r++;
  }
  return r;
}
//
// 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 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Expected EOLN
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Expected EOLN
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 Expected EOLN
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Expected EOLN
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 844 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 844 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -