Submission #426938

# Submission time Handle Problem Language Result Execution time Memory
426938 2021-06-14T11:02:47 Z ollel Sorting (IOI15_sorting) C++17
Compilation error
0 ms 0 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[]) {
      |                                                   ~~~~^~~
sorting.cpp: In function 'int main()':
sorting.cpp:77:44: warning: 'M' is used uninitialized in this function [-Wuninitialized]
   77 |   cout << findSwapPairs(n, S, M, X, Y, P, Q) << endl;
      |                                            ^
sorting.cpp:78:33: warning: ''target_mem_ref' not supported by dump_expr<expression error>' may be used uninitialized in this function [-Wmaybe-uninitialized]
   78 |   rep (i, 0, 5) cout << P[i] << " " << Q[i] << endl;
      |                                 ^~~
sorting.cpp:78:43: warning: ''target_mem_ref' not supported by dump_expr<expression error>' may be used uninitialized in this function [-Wmaybe-uninitialized]
   78 |   rep (i, 0, 5) cout << P[i] << " " << Q[i] << endl;
      |                                           ^
/usr/bin/ld: /tmp/cc4atPOZ.o: in function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'; /tmp/ccFsWaF0.o:sorting.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status