Submission #314880

# Submission time Handle Problem Language Result Execution time Memory
314880 2020-10-21T14:58:29 Z tengiz05 Sorting (IOI15_sorting) C++17
0 / 100
2 ms 512 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int n, m;
int x[N], y[N], pos[N], a[N];
vector<pair<int, int>> v;
bool check(int mid){
	v.clear();
	for(int i=0;i<n;i++)pos[a[i]] = i;
	vector<bool> used(n);
	for(int i=0;i<mid;i++){
		swap(pos[a[x[i]]], pos[a[y[i]]]);
		swap(a[x[i]], a[y[i]]);
	}int ans = 0;
	for(int i=0;i<n;i++){
		if(pos[i] == i){
			continue;
		}else {
			ans++;
			int f = pos[i], s = i;
			swap(pos[i], pos[a[i]]);
			swap(a[f], a[s]);
			v.push_back({f, s});
		}
	}
	return (ans <= mid);
}
int findSwapPairs(int NN, int A[], int MM, int X[], int Y[], int P[], int Q[]) {
	n = NN, m = MM;
	int l = 0, r = n;
	for(int i=0;i<m;i++){
		x[i] = X[i];
		y[i] = Y[i];
	}
	while(l+1 < r){
		for(int i=0;i<n;i++)a[i] = A[i];
		int mid = (l+r)/2;
		if(check(mid)){
			r = mid;
		}else {
			l = mid;
		}
	}
	check(r);
	for(int i=0;i<r;i++){
		if(i < v.size()){
			P[i] = v[i].first;
			Q[i] = v[i].second;
		}else {
			P[i] = Q[i] = 0;
		}
	}
	return r;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:47:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   if(i < v.size()){
      |      ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -