Submission #1041981

# Submission time Handle Problem Language Result Execution time Memory
1041981 2024-08-02T11:36:40 Z fv3 Sorting (IOI15_sorting) C++14
0 / 100
2 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[]) 
{
	// X[i] = Y[i] = 0
	int cnt = 0;
    for (int i = 0; i < N; i++)
    {
    	int l = 2;
    	for (; l < N; l++)
    	{
    		if (S[l] != l)
    			break;
    	}

    	if (l == N)
    		break;

    	swap(S[0], S[1]);

    	cnt++;
    	P[i] = (i == 1 ? 0 : i);

    	for (int j = 0; j < N; j++)
    	{
    		if (S[j] == i)
    		{
    			Q[i] = j;
    			if (i != j)
    				swap(S[P[i]], S[j]);
    		}
    	}
    }

	if (S[0] == 0)
		return cnt;

	P[cnt-1] = 0;
	Q[cnt-1] = 0;
	return cnt;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:6:39: warning: unused parameter 'M' [-Wunused-parameter]
    6 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[])
      |                                   ~~~~^
sorting.cpp:6:46: warning: unused parameter 'X' [-Wunused-parameter]
    6 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[])
      |                                          ~~~~^~~
sorting.cpp:6:55: warning: unused parameter 'Y' [-Wunused-parameter]
    6 | 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 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -