Submission #60137

# Submission time Handle Problem Language Result Execution time Memory
60137 2018-07-23T17:35:02 Z dukati8 Sorting (IOI15_sorting) C++14
0 / 100
2 ms 384 KB
#include "sorting.h"
#include <bits/stdc++.h>
#define rep(i,a,b) for (int i=a; i<int(b); i++)
using namespace std;

vector<pair<int, int> > moves;
int movestofix(int I[],int S[], int N) {
  moves.clear();
  //I[i] is not value at i, but index of value i in S
  int counter=0;
  rep(i,0,N) {
    if (S[i]==i) continue;
    counter++;
    int a,b;
    a=i;
    b=I[i];
    //a och b byter plats
    int sa,sb;
    sa=S[a];
    sb=S[b];
    moves.push_back(make_pair(a,b));
    S[a]=sb;
    S[b]=sa;
    I[sa]=b;
    I[sb]=a;

  }
  moves.push_back(make_pair(0,0));
  return counter;
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
  int I[N];
  rep (i,0,N) {
    I[S[i]]=i;
  }
  int i=0;
  while (movestofix(I,S,N)>i) {

    int a,b;
    a=X[i];
    b=Y[i];
    //a och b byter plats
    int sa,sb;
    sa=S[a];
    sb=S[b];
    S[a]=sb;
    S[b]=sa;
    I[sa]=b;
    I[sb]=a;
    i++;
  }
  for (int j=i-1;j>=0; j--) {
    P[j]=moves[j].first;
    Q[j]=moves[j].second;
    rep (k,0,j-1) {
      if (moves[j].first==X[j]) moves[j].first=Y[j];
      else if (moves[j].first==Y[j]) moves[j].first=X[j];
      if (moves[j].second==X[j]) moves[j].second=Y[j];
      else if (moves[j].second==Y[j]) moves[j].second=X[j];
    }
  }
  return i;
}

Compilation message

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