Submission #426096

# Submission time Handle Problem Language Result Execution time Memory
426096 2021-06-13T13:57:39 Z _fractal Sorting (IOI15_sorting) C++14
36 / 100
1000 ms 620 KB
#include "sorting.h"
#include <iostream>
#include <algorithm>
using namespace std;
 

int findSwapPairs(int N, int SS[], int M, int X[], int Y[], int P[], int Q[]) {
	int A[N], pos[N], L[M], R[M], ret = (1<<30), S[N];
	for (int m = 0; m < M; ++m) {
		for (int i = 0; i < N; ++i)
			A[i] = i, S[i] = SS[i];
		for (int i = m; i >= 0; --i)
			swap(A[X[i]], A[Y[i]]);
		int r = -1;
		for (int i = 0; i <= m; ++i) {
			P[i] = Q[i] = 0;
			bool f = 1;
			for (int j = 1; j < N; ++j)
				if (S[j - 1] > S[j])
					f = 0;
			if (f) {
				r = i;
				break;
			}
			swap(S[X[i]], S[Y[i]]);
			swap(A[X[i]], A[Y[i]]);
			f = 1;
			for (int j = 1; j < N; ++j)
				if (S[j - 1] > S[j])
					f = 0;
			if (f) {
				r = i + 1;
				break;
			}
			for (int j = 0; j < N; ++j)
				pos[A[j]] = j;
			for (int j = 0; j < N; ++j) {
				if (pos[S[j]] != j) {
					Q[i] = j, P[i] = pos[S[j]];
					break;
				}
			}
			swap(S[Q[i]], S[P[i]]);
		}
		bool f = 1;
		for (int i = 1; i < N; ++i)
			if (S[i - 1] > S[i])
				f = 0;
		if (!f) continue;
		if (r == -1) r = m + 1;
		if (ret >= r) {
			ret = r;
			for (int i = 0; i < r; ++i)
				L[i] = Q[i], R[i] = P[i];
		}
	}
	for (int i = 0; i < ret; ++i)
		Q[i] = L[i], P[i]= R[i];
	for (int i = 0; i < ret; ++i)
		cerr << X[i] << " " << Y[i] << "\n" << P[i] << " " << Q[i] << '\n';
	return ret;
}

# 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 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 1 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 1 ms 204 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 175 ms 332 KB Output is correct
11 Correct 162 ms 384 KB Output is correct
12 Correct 148 ms 452 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 144 ms 332 KB Output is correct
4 Correct 176 ms 344 KB Output is correct
5 Correct 168 ms 344 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 1 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 1 ms 204 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 175 ms 332 KB Output is correct
11 Correct 162 ms 384 KB Output is correct
12 Correct 148 ms 452 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 144 ms 332 KB Output is correct
16 Correct 176 ms 344 KB Output is correct
17 Correct 168 ms 344 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 292 KB Output is correct
21 Execution timed out 1076 ms 620 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 492 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 492 KB Time limit exceeded
2 Halted 0 ms 0 KB -