Submission #426039

#TimeUsernameProblemLanguageResultExecution timeMemory
426039_fractalSorting (IOI15_sorting)C++14
20 / 100
47 ms368 KiB
#include "sorting.h"
#include <iostream>
#include <algorithm>
using namespace std;
 
 
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	int A[N], pos[N];
	for (int i = 0; i < N; ++i)
		A[i] = i;
	for (int i = M - 1; i >= 0; --i)
		swap(A[X[i]], A[Y[i]]);
	int r = 0;
	bool f = 1;
	for (int j = 1; j < N; ++j)
		if (S[j - 1] > S[j])
			f = 0;
	if (f)
		return r;
	for (int i = 0; i < M; ++i) {
		swap(S[X[i]], S[Y[i]]);
		swap(A[X[i]], A[X[i]]);
		bool f = 1;
		for (int j = 1; j < N; ++j)
			if (S[j - 1] > S[j])
				f = 0;
		if (f) {
			++r;
			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]];
				++r;
				break;
			}
		}
		f = 1;
		swap(S[Q[i]], S[P[i]]);
		for (int j = 1; j < N; ++j)
			if (S[j - 1] > S[j])
				f = 0;
		if (f)
			break;
	}
	return r;
}

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:23:8: warning: declaration of 'f' shadows a previous local [-Wshadow]
   23 |   bool f = 1;
      |        ^
sorting.cpp:14:7: note: shadowed declaration is here
   14 |  bool f = 1;
      |       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...