Submission #764850

# Submission time Handle Problem Language Result Execution time Memory
764850 2023-06-24T05:41:58 Z SanguineChameleon Sorting (IOI15_sorting) C++17
Compilation error
0 ms 0 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;

const int maxN = 2e5 + 20;
int cnt[maxN];

mt19937 gen(69420);

bool cmp(int i, int j) {
	return cnt[i] < cnt[j];
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	for (int i = 0; i < M; i++) {
		cnt[X[i]]++;
		cnt[Y[i]]++;
	}
	int len = 0;
	for (int i = 0; ; i++) {
		bool ok = true;
		for (int j = 0; j < N; j++) {
			if (S[j] != j) {
				ok = false;
				break;
			}
		}
		if (ok) {
			return len;
		}
		assert(i < M);
		cnt[X[i]]--;
		cnt[Y[i]]--;
		swap(S[X[i]], S[Y[i]]);
		vector<int> wrong;
		for (int j = 0; j < N; j++) {
			if (S[j] != j) {
				wrong.push_back(j);
			}
		}
		if (wrong.empty()) {
			P[len] = 0;
			Q[len] = 0;
		}
		else {
			if ((int)wrong.size() >= 10) {
				sort(wrong.begin(), wrong.end(), cmp);
				shuffle(wrong.begin(), wrong.begin() + 10);
			}
			else {
				shuffle(wrong.begin(), wrong.end(), gen);
			}
			P[len] = wrong[0];
			for (int j = 0; j < N; j++) {
				if (S[j] == wrong[0]) {
					Q[len] = j;
					break;
				}
			}
		}
		swap(S[P[len]], S[Q[len]]);
		len++;
	}
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:48:46: error: no matching function for call to 'shuffle(std::vector<int>::iterator, __gnu_cxx::__normal_iterator<int*, std::vector<int> >)'
   48 |     shuffle(wrong.begin(), wrong.begin() + 10);
      |                                              ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from sorting.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3748:5: note: candidate: 'template<class _RAIter, class _UGenerator> void std::shuffle(_RAIter, _RAIter, _UGenerator&&)'
 3748 |     shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~~~~
/usr/include/c++/10/bits/stl_algo.h:3748:5: note:   template argument deduction/substitution failed:
sorting.cpp:48:46: note:   candidate expects 3 arguments, 2 provided
   48 |     shuffle(wrong.begin(), wrong.begin() + 10);
      |                                              ^