Submission #1092714

# Submission time Handle Problem Language Result Execution time Memory
1092714 2024-09-24T19:45:16 Z triplem5ds Sorting (IOI15_sorting) C++14
20 / 100
1 ms 600 KB
#include "sorting.h"
#include "bits/stdc++.h"

using namespace std;

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {

	vector<pair<int, int>> ans;
	auto check = [&](int prefix) {
		ans.clear();
		vector<int> vec(N), vis(N, 0), pos(N);
		copy(S, S + N, vec.begin());
		for (int i = 0; i < prefix; i++) swap(vec[X[i]], vec[Y[i]]);
		for (int i = 0; i < N; i++) {
			int cur = i;
			vis[cur] = 1;
			while (!vis[vec[cur]])
			{
				ans.push_back({ cur,vec[cur] });
				cur = vec[cur];
				vis[cur] = 1;
			}
		}
		return ans.size() <= prefix;

		};



	int lo = 0, hi = M;

	while (lo < hi)
	{
		int md = lo + (hi - lo) / 2;

		if (check(md))	hi = md;
		else lo = md + 1;
	}


	reverse(ans.begin(), ans.end());
	while (ans.size() <= lo) ans.push_back({ 0, 0 });
	vector<int> pos(N), vec(N);
	for (int i = 0; i < N; i++) {
		pos[i] = vec[i] = i;
	}
	for (int i = lo - 1; i >= 0; --i) {
		P[i] = pos[ans[i].first];
		Q[i] = pos[ans[i].second];
		swap(pos[vec[X[i]]], pos[vec[Y[i]]]);
		swap(vec[X[i]], vec[Y[i]]);
	}

	return lo;
}


Compilation message

sorting.cpp: In lambda function:
sorting.cpp:24:21: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |   return ans.size() <= prefix;
      |          ~~~~~~~~~~~^~~~~~~~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:42:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |  while (ans.size() <= lo) ans.push_back({ 0, 0 });
      |         ~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -