Submission #137997

# Submission time Handle Problem Language Result Execution time Memory
137997 2019-07-28T19:49:17 Z arthurconmy Sorting (IOI15_sorting) C++14
0 / 100
1000 ms 376 KB
#include <bits/stdc++.h>
using namespace std;

int eend[501];

int findSwapPairs(int n, int S[], int m, int X[], int Y[], int P[], int Q[])
{
	// cout << n << endl;

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

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

	//f//or(int i=0; i<n; i++)
	//{
		//cout << i << " " << eend[i] << endl;
	//}

	// return 7;

	int cur_sort=0;

	// cout << "HERE" << endl;

	for(int i=0; i<m; i++)
	{
		//cout << i << endl;

		swap(eend[X[i]],eend[Y[i]]);
		swap(S[X[i]],S[Y[i]]);

		bool upd=0;

		while(cur_sort < n)
		{
			// find cur_sort in both arrays

			int pos_s=-1;
			int pos_e=-1;

			for(int j=0; j<n; i++)
			{
				if(S[j]==cur_sort) pos_s=j;
				if(eend[j]==cur_sort) pos_e=j;
			}

			if(pos_e == pos_s)
			{
				// cout << cur_sort << " is sorted bro" << endl;

				cur_sort++;
				continue;
			}

			swap(S[pos_s],S[pos_e]);
			P[i]=pos_s;
			Q[i]=pos_e;
			upd=1;

			cur_sort++;
			break;
		}

		if(!upd)
		{
			P[i]=0;
			Q[i]=0;
		}

		// cout << P[i] << " " << Q[i] << endl;
	}

	return m;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1065 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1065 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -