Submission #921752

# Submission time Handle Problem Language Result Execution time Memory
921752 2024-02-04T09:50:20 Z coding_snorlax Sorting (IOI15_sorting) C++14
16 / 100
5 ms 348 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[]) {
    for(int i=2;i<N;i++){
        int tmp = S[X[i-2]];
        S[X[i-2]]=S[Y[i-2]];
        S[Y[i-2]]=tmp;
        for(int j=0;j<N;j++){
            if(S[j]==i){
                P[i-2]=j;
                Q[i-2]=i;
                S[j]=S[i];
                S[i]=i;
                break;
            }
        }
        // check already_sorted
        int flag = 1;
        for(int j=0;j<N;j++){
            if(S[j]!=j) flag =0;
        }
        if(flag){
            return i-1;
        }
    }
    int tmp = S[X[N-2]];
    S[X[N-2]]=S[Y[N-2]];
    S[Y[N-2]]=tmp;
    if(S[0]!=0){P[N-2]=0;Q[N-2]=1;}
    else {P[N-2]=0;Q[N-2]=0;}
	return N-1;
}

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[]) {
      |                                   ~~~~^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -