Submission #288363

# Submission time Handle Problem Language Result Execution time Memory
288363 2020-09-01T12:48:56 Z Saboon Sorting (IOI15_sorting) C++17
100 / 100
272 ms 28024 KB
#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, x[3*maxn], y[3*maxn], a[maxn], b[maxn], pos[maxn], mex[3*maxn], mey[3*maxn];
bool mark[maxn];

bool check(int Q){
	for (int i = 0; i < n; i++){
		b[i] = a[i];
		pos[a[i]] = i;
	}
	for (int i = 0; i < Q; i++)
		swap(a[x[i]], a[y[i]]);
	int cnt = 0;
	memset(mark, 0, sizeof mark);
	for (int i = 0; i < n; i++){
		int now = i;
		mark[now] = 1;
		while (!mark[a[now]]){
			int last = now;
			now = a[now];
			mark[now] = 1;
			swap(b[x[cnt]], b[y[cnt]]);
			swap(pos[b[x[cnt]]], pos[b[y[cnt]]]);
			mex[cnt] = pos[now], mey[cnt] = pos[last];
			swap(pos[now],pos[last]);
			swap(b[pos[now]], b[pos[last]]);
			cnt ++;
		}
	}
	for (int i = cnt; i < Q; i++)
		mex[i] = mey[i] = 0;
	if (cnt <= Q)
		return true;
	return false;
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]){
	n = N;
	for (int i = 0; i < M; i++)
		x[i] = X[i], y[i] = Y[i];
	int lo = -1, hi = M;
	while (hi-lo > 1){
		int mid = (lo + hi) >> 1;
		for (int i = 0; i < n; i++)
			a[i] = S[i];
		if (check(mid))
			hi = mid;
		else
			lo = mid;
	}
	for (int i = 0; i < n; i++)
		a[i] = S[i];
	check(hi);
	for (int i = 0; i < hi; i++)
		P[i] = mex[i], Q[i] = mey[i];
	return hi;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 640 KB Output is correct
12 Correct 1 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 672 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 1 ms 640 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 640 KB Output is correct
12 Correct 1 ms 640 KB Output is correct
13 Correct 1 ms 672 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 1 ms 640 KB Output is correct
17 Correct 1 ms 640 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 2 ms 896 KB Output is correct
22 Correct 2 ms 896 KB Output is correct
23 Correct 2 ms 896 KB Output is correct
24 Correct 2 ms 896 KB Output is correct
25 Correct 2 ms 896 KB Output is correct
26 Correct 2 ms 896 KB Output is correct
27 Correct 2 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 2 ms 768 KB Output is correct
3 Correct 2 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 2 ms 768 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Correct 2 ms 768 KB Output is correct
12 Correct 2 ms 768 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 1 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 2 ms 768 KB Output is correct
3 Correct 2 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 2 ms 768 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Correct 2 ms 768 KB Output is correct
12 Correct 2 ms 768 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 1 ms 768 KB Output is correct
15 Correct 197 ms 17468 KB Output is correct
16 Correct 218 ms 25720 KB Output is correct
17 Correct 272 ms 26924 KB Output is correct
18 Correct 94 ms 22264 KB Output is correct
19 Correct 182 ms 25464 KB Output is correct
20 Correct 199 ms 26232 KB Output is correct
21 Correct 194 ms 26488 KB Output is correct
22 Correct 202 ms 22520 KB Output is correct
23 Correct 220 ms 28024 KB Output is correct
24 Correct 270 ms 27640 KB Output is correct
25 Correct 262 ms 27256 KB Output is correct
26 Correct 196 ms 26384 KB Output is correct
27 Correct 166 ms 25592 KB Output is correct
28 Correct 269 ms 27512 KB Output is correct
29 Correct 252 ms 26872 KB Output is correct
30 Correct 140 ms 24952 KB Output is correct
31 Correct 265 ms 27384 KB Output is correct
32 Correct 216 ms 26872 KB Output is correct
33 Correct 266 ms 27640 KB Output is correct
34 Correct 232 ms 27512 KB Output is correct
35 Correct 181 ms 25208 KB Output is correct
36 Correct 74 ms 23928 KB Output is correct
37 Correct 268 ms 27768 KB Output is correct
38 Correct 256 ms 27128 KB Output is correct
39 Correct 256 ms 26744 KB Output is correct