Submission #48231

# Submission time Handle Problem Language Result Execution time Memory
48231 2018-05-11T01:35:16 Z cheater2k Sorting (IOI15_sorting) C++17
20 / 100
4 ms 512 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 200005;

int n, m;
int s[MAXN];
int pa[MAXN], pb[MAXN], b[MAXN];
int x[MAXN * 3], y[MAXN * 3];
vector < pair<int,int> > vres;

bool check(int k) {
	vres.clear();
	for (int i = 0; i < n; ++i) {
		b[i] = i;
	}
	for (int i = 0; i < k; ++i) {
		swap(b[x[i]], b[y[i]]);
	}

	// the swaps must satisfy: s[i] = b[i]
	for (int i = 0; i < n; ++i) {
		pb[s[i]] = b[i];
		pa[b[i]] = s[i];
	}

	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		if (pa[i] != i) {
			++cnt;
			// TODO: swap i, pb[i]
			int j = pb[i];
			vres.push_back(make_pair(i, j));
			int p = pa[i], q = pa[j];
			swap(pa[i], pa[j]);
			pb[q] = i;
			pb[p] = j;
		}
	}

	return cnt <= k;
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	n = N;
	m = M;
  for (int i = 0; i < n; ++i) s[i] = S[i];
  for (int i = 0; i < m; ++i) x[i] = X[i], y[i] = Y[i];
  
  int low = 0, high = m;
  while(low < high) {
  	int mid = ((low + high) >> 1);
  	if (check(mid)) high = mid;
  	else low = mid + 1;
  }

  check(low);
  for (int i = 0; i < low; ++i) {
  	P[i] = vres[i].first;
  	Q[i] = vres[i].second;
  }
  return low;
}


# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Incorrect 2 ms 384 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -