Submission #428294

# Submission time Handle Problem Language Result Execution time Memory
428294 2021-06-15T09:46:30 Z haxorman Sorting (IOI15_sorting) C++14
36 / 100
1000 ms 516 KB
#include "sorting.h"
#include "bits/stdc++.h"
using namespace std;

const int mxN = 2e5 + 7;

int n, m, arr[mxN], freq[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];
	}

	for (int i = 0; i < m; ++i) {
		freq[X[i]]++;
		freq[Y[i]]++;
	}

	int R = 0;
	bool ok = false;
	for (int ind = 0; ind < m; ++ind) {
		ok = true;
		for (int i = 0; i < n; ++i) {
			if (arr[i] != i) {
				ok = false;
			}
		}

		if (ok) {
			break;
		}
		
		swap(arr[X[ind]], arr[Y[ind]]);
		freq[X[ind]]--;
		freq[Y[ind]]--;

		ok = true;
		for (int i = 0; i < n; ++i) {
			if (arr[i] != i) {
				ok = false;
			}
		}

		if (ok) {
			P[ind] = Q[ind] = 0;
			++R;
			break;
		}

		bool stop = false;
		for (int i = 0; i < n && !stop; ++i) {
			if (freq[i])
				continue;

			for (int j = 0; j < n && !stop; ++j) {
				if (arr[j] == i && i != j) {
					swap(arr[j], arr[i]);
					P[ind] = j, Q[ind] = i;
					++R;
					stop = true;
				}
			}
		}

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

	}

	return R;
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Incorrect 38 ms 516 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 488 KB Time limit exceeded
2 Halted 0 ms 0 KB -