Submission #830637

# Submission time Handle Problem Language Result Execution time Memory
830637 2023-08-19T08:47:07 Z Shithila Sorting (IOI15_sorting) C++14
16 / 100
1 ms 340 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
int findSwapPairs(int N, int s[], int M, int X[], int Y[], int P[], int Q[]) {
  int pos[N];
  int ind=0;
  for(int i=0;i<N;i++) pos[s[i]]=i;
  int k;
  int x;
  if(s[0]==0 && s[1]==1)
  {
     ind=0;
  }
  else if(s[0]==0)
  {
     k=s[0];
      pos[s[0]]=1;
      pos[s[1]]=0;
      s[0]=s[1];
      s[1]=k;
    P[ind]=1;
    Q[ind]=pos[1];
  x=pos[1];
    pos[1]=1;
    pos[s[1]]=x;
    s[x]=s[1];
    s[1]=1;
    ind++;
  }
  else if(s[1]==1)
  {
     k=s[0];
      pos[s[0]]=1;
      pos[s[1]]=0;
      s[0]=s[1];
      s[1]=k;
      P[ind]=0;
      Q[ind]=pos[0];
      x=pos[0];
      pos[0]=0;
      pos[s[0]]=x;
      s[x]=s[0];
      s[0]=0;
      ind++;
  }
  else
  {
     k=s[0];
      pos[s[0]]=1;
      pos[s[1]]=0;
      s[0]=s[1];
      s[1]=k;
    P[ind]=0;
    Q[ind]=pos[0];
     x=pos[0];
    pos[0]=0;
    pos[s[0]]=x;
    s[x]=s[0];
    s[0]=0;
    ind++;
     k=s[0];
      pos[s[0]]=1;
      pos[s[1]]=0;
      s[0]=s[1];
      s[1]=k;
    P[ind]=0;
    Q[ind]=pos[1];
     x=pos[1];
    pos[1]=0;
    pos[s[0]]=x;
    s[x]=s[0];
    s[0]=1;
    ind++;
  }
  for(int i=2;i<N;i++)
  {
    //ind++;
    
    if(i==s[i]) continue;
    k=s[0];
     pos[s[0]]=1;
     pos[s[1]]=0;
     s[0]=s[1];
     s[1]=k;
      P[ind]=i;
      Q[ind]=pos[i];
       x=pos[i];
      pos[i]=i;
      pos[s[i]]=x;
      s[x]=s[i];
      s[i]=i;
      ind++;


    }
    if(s[0]!=0)
    {
      ind++;
    P[ind]=0;
    Q[ind]=1;
    }
    return ind;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:4:39: warning: unused parameter 'M' [-Wunused-parameter]
    4 | int findSwapPairs(int N, int s[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
sorting.cpp:4:46: warning: unused parameter 'X' [-Wunused-parameter]
    4 | int findSwapPairs(int N, int s[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                          ~~~~^~~
sorting.cpp:4:55: warning: unused parameter 'Y' [-Wunused-parameter]
    4 | int findSwapPairs(int N, int s[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                                   ~~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Integer 1 violates the range [0, 0]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Integer 1 violates the range [0, 0]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Integer 1 violates the range [0, 0]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -