Submission #60142

# Submission time Handle Problem Language Result Execution time Memory
60142 2018-07-23T17:51:03 Z dukati8 Sorting (IOI15_sorting) C++14
36 / 100
40 ms 496 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 Ii[],int Ss[], int N) {
  int I[N], S[N];
  rep (i,0,N) { I[i]=Ii[i];S[i]=Ss[i];}
  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++;
  }
  int switches[N];
  rep (i,0,N) switches[i]=i;

  for (int j=i-1;j>=0; j--) {
    P[j]=switches[moves[j].first];
    Q[j]=switches[moves[j].second];
    swap(switches[X[j]],switches[Y[j]]);
  }
  return i;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:56:8: warning: declaration of 'i' shadows a previous local [-Wshadow]
   rep (i,0,N) switches[i]=i;
        ^
sorting.cpp:3:29: note: in definition of macro 'rep'
 #define rep(i,a,b) for (int i=a; i<int(b); i++)
                             ^
sorting.cpp:39:7: note: shadowed declaration is here
   int i=0;
       ^
sorting.cpp:34: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 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 356 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Incorrect 5 ms 384 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 496 KB Output isn't correct
2 Halted 0 ms 0 KB -