Submission #285417

# Submission time Handle Problem Language Result Execution time Memory
285417 2020-08-28T22:43:48 Z amiratou Sorting (IOI15_sorting) C++14
100 / 100
265 ms 13176 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define sz(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;

int tab[200005],pos[200005],L;
ii ans[200005];

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	int l=0,r=N-1;
	while(l<=r){
		for (int i = 0; i < N; ++i){
			tab[i]=S[i];
			pos[S[i]]=i;
		}
		int med=(l+r)>>1,idx=0;
		for (int i = 0; i < med; ++i)
			swap(pos[tab[X[i]]],pos[tab[Y[i]]]),swap(tab[X[i]],tab[Y[i]]);
		for (int i = 0; i < N; ++i)
		{
			if(tab[i]!=i){
				int k=pos[i];
				ans[idx++]={i,tab[i]};
				swap(pos[tab[i]],pos[i]);
				swap(tab[i],tab[k]);

			}
		}
		if(idx>med)l=med+1;
		else{
			L=med;
			for (int i = 0; i < N; ++i){
				tab[i]=S[i];
				pos[S[i]]=i;
			}
			for (int i = 0; i < med; ++i)
			{
				swap(pos[tab[X[i]]],pos[tab[Y[i]]]),swap(tab[X[i]],tab[Y[i]]);
				if(i<idx)P[i]=pos[ans[i].fi],Q[i]=pos[ans[i].se],swap(tab[P[i]],tab[Q[i]]),swap(pos[ans[i].fi],pos[ans[i].se]);
				else P[i]=Q[i]=0;
			}
			r=med-1;
		}
		
	}
	return L;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:13:39: warning: unused parameter 'M' [-Wunused-parameter]
   13 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 151 ms 11704 KB Output is correct
16 Correct 174 ms 11896 KB Output is correct
17 Correct 217 ms 12536 KB Output is correct
18 Correct 83 ms 8320 KB Output is correct
19 Correct 170 ms 9976 KB Output is correct
20 Correct 206 ms 11128 KB Output is correct
21 Correct 205 ms 11004 KB Output is correct
22 Correct 163 ms 12792 KB Output is correct
23 Correct 155 ms 13048 KB Output is correct
24 Correct 231 ms 12792 KB Output is correct
25 Correct 218 ms 12664 KB Output is correct
26 Correct 155 ms 10640 KB Output is correct
27 Correct 196 ms 10108 KB Output is correct
28 Correct 265 ms 12536 KB Output is correct
29 Correct 226 ms 12156 KB Output is correct
30 Correct 155 ms 9080 KB Output is correct
31 Correct 260 ms 12408 KB Output is correct
32 Correct 166 ms 12524 KB Output is correct
33 Correct 238 ms 12792 KB Output is correct
34 Correct 217 ms 12792 KB Output is correct
35 Correct 183 ms 9848 KB Output is correct
36 Correct 69 ms 8056 KB Output is correct
37 Correct 218 ms 13176 KB Output is correct
38 Correct 210 ms 12664 KB Output is correct
39 Correct 207 ms 12664 KB Output is correct