Submission #135300

# Submission time Handle Problem Language Result Execution time Memory
135300 2019-07-24T02:41:00 Z 20160161simone Sorting (IOI15_sorting) C++14
100 / 100
312 ms 21944 KB
#include "sorting.h"
#include <bits/stdc++.h>
#define NN 200010
using namespace std;
int a[NN],b[NN],c[NN][2],*x,*y,*s,k,n,m;
bool check(int m0)
{
	for(int i=0;i<n;i++) a[i]=s[i];
	for(int i=0;i<m0;i++) swap(a[x[i]],a[y[i]]);
	for(int i=0;i<n;i++) b[a[i]]=i;
	k=0;
	for(int i=0;i<n;i++)
	{
		if(b[i]!=i)
		{
			c[k][0]=i,c[k][1]=a[i];
			swap(a[b[i]],a[b[c[k][1]]]);
			swap(b[i],b[c[k][1]]);
			k++;
		}
	}
	if(k<=m0) return 1;
	return 0;
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    n=N,m=M,x=X,y=Y,s=S;
    int l=0,r=m,ans_num=m;
    while(l<=r)
	{
    	int mid=(l+r)/2;
    	if(check(mid)==1) ans_num=mid,r=mid-1;
    	else l=mid+1;
	}
	check(ans_num);
	for(int i=0;i<n;i++) a[i]=s[i];
	for(int i=0;i<n;i++) b[a[i]]=i;
	for(int i=0;i<ans_num;i++)
	{
		swap(a[x[i]],a[y[i]]);
		swap(b[a[x[i]]],b[a[y[i]]]);
		if(i<k)
		{
			swap(a[P[i]=b[c[i][0]]],a[Q[i]=b[c[i][1]]]);
			swap(b[c[i][0]],b[c[i][1]]);
		}
		else Q[i]=0,P[i]=0;
	}
	return ans_num;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 508 KB Output is correct
22 Correct 3 ms 632 KB Output is correct
23 Correct 3 ms 632 KB Output is correct
24 Correct 3 ms 632 KB Output is correct
25 Correct 3 ms 632 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 480 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 480 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 179 ms 19376 KB Output is correct
16 Correct 184 ms 19832 KB Output is correct
17 Correct 223 ms 20856 KB Output is correct
18 Correct 80 ms 16376 KB Output is correct
19 Correct 167 ms 19064 KB Output is correct
20 Correct 184 ms 19804 KB Output is correct
21 Correct 176 ms 19832 KB Output is correct
22 Correct 179 ms 16292 KB Output is correct
23 Correct 201 ms 21624 KB Output is correct
24 Correct 228 ms 21368 KB Output is correct
25 Correct 312 ms 21112 KB Output is correct
26 Correct 181 ms 19428 KB Output is correct
27 Correct 157 ms 18424 KB Output is correct
28 Correct 220 ms 21112 KB Output is correct
29 Correct 207 ms 20472 KB Output is correct
30 Correct 127 ms 17528 KB Output is correct
31 Correct 221 ms 20852 KB Output is correct
32 Correct 199 ms 20936 KB Output is correct
33 Correct 263 ms 21368 KB Output is correct
34 Correct 238 ms 21300 KB Output is correct
35 Correct 209 ms 18992 KB Output is correct
36 Correct 76 ms 16004 KB Output is correct
37 Correct 264 ms 21944 KB Output is correct
38 Correct 247 ms 21080 KB Output is correct
39 Correct 259 ms 21192 KB Output is correct