Submission #428012

# Submission time Handle Problem Language Result Execution time Memory
428012 2021-06-15T07:13:50 Z haxorman Sorting (IOI15_sorting) C++14
0 / 100
164 ms 368 KB
#include "sorting.h"
#include "bits/stdc++.h"
using namespace std;

const int mxN = 2e5 + 7;

int n, m, arr[mxN];

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	n = N, m = M;

	for (int i = 0; i < n; ++i) {
		arr[i] = S[i];
	}
	sort(S, S + n);

	int R = 0, ind = 0;
	bool subtask_3 = (Y[ind] != 0);

	int start = 0;
	if (subtask_3) {
		swap(arr[0], arr[1]);
		for (int i = 0; i < 2; ++i) {
			for (int j = 0; j < n; ++j) {
				if (arr[j] == S[i] && j != 1) {
					swap(arr[j], arr[1]);
					P[ind] = j, Q[ind] = 1;
					++R;
					++ind;
					break;
				}
			}
		}
		start = 2;
	}


	for (int iter = 1; iter <= 50; ++iter) {
		for (int i = start; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (arr[j] == S[i] && i != j) {
					swap(arr[j], arr[i]);
					P[ind] = j, Q[ind] = i;
					++R;
					++ind;
					break;
				}
			}
		}
	}

	if (subtask_3) {
		for (int i = 1; i < R; ++i) {
			swap(arr[0], arr[1]);
		}
	}

	if (arr[0] != 0) {
		P[ind] = 0, Q[ind] = 1;
		++R;
		++ind; 
	}

	if (!R) {
		P[0] = 0;
		Q[0] = 0;
		R = 1;
	}
	return R;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:9:46: warning: unused parameter 'X' [-Wunused-parameter]
    9 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                          ~~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 164 ms 368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 164 ms 368 KB Output isn't correct
2 Halted 0 ms 0 KB -