답안 #52856

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52856 2018-06-27T05:18:48 Z tmwilliamlin168 정렬하기 (IOI15_sorting) C++14
100 / 100
214 ms 11640 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;

const int mxN=2e5;
int a[mxN], b[mxN];
bool vis[mxN];

int findSwapPairs(int n, int *s, int m, int *x, int *y, int *p, int *q) {
	int lb=0, rb=n-1, mb, ss;
	while(lb<=rb) {
		mb=(lb+rb)/2, ss=0;
		memcpy(a, s, 4*n);
		for(int i=0; i<mb; ++i)
			swap(a[x[i]], a[y[i]]);
		memset(vis, 0, n);
		for(int i=0; i<n; ++i) {
			if(vis[i])
				continue;
			vis[i]=1;
			for(int j=i; !vis[a[j]]; j=a[j]) {
				vis[a[j]]=1;
				++ss;
			}
		}
		if(ss<=mb)
			rb=mb-1;
		else
			lb=mb+1;
	}
	ss=0;
	memcpy(a, s, 4*n);
	for(int i=0; i<lb; ++i)
		swap(a[x[i]], a[y[i]]);
//	for(int i=0; i<n; ++i)
//		cout << a[i] << " ";
//	cout << endl;
	memset(vis, 0, n);
	for(int i=0; i<n; ++i)
		b[s[i]]=i;
	for(int i=0; i<n; ++i) {
		if(vis[i])
			continue;
		vis[i]=1;
		for(int j=i; !vis[a[j]]; j=a[j]) {
			vis[a[j]]=1;
			swap(s[x[ss]], s[y[ss]]);
			b[s[x[ss]]]=x[ss];
			b[s[y[ss]]]=y[ss];
			p[ss]=b[a[j]];
			q[ss]=b[a[a[j]]];
			swap(s[p[ss]], s[q[ss]]);
			b[s[p[ss]]]=p[ss];
			b[s[q[ss]]]=q[ss];
			++ss;
		}
	}
	memset(p+ss, 0, 4*(lb-ss));
	memset(q+ss, 0, 4*(lb-ss));
	return lb;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:9:38: warning: unused parameter 'm' [-Wunused-parameter]
 int findSwapPairs(int n, int *s, int m, int *x, int *y, int *p, int *q) {
                                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 3 ms 412 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 3 ms 412 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 636 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 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 3 ms 512 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 4 ms 512 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 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 3 ms 512 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 4 ms 512 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 196 ms 9752 KB Output is correct
16 Correct 143 ms 9924 KB Output is correct
17 Correct 206 ms 10680 KB Output is correct
18 Correct 51 ms 7032 KB Output is correct
19 Correct 158 ms 9208 KB Output is correct
20 Correct 138 ms 9592 KB Output is correct
21 Correct 158 ms 9796 KB Output is correct
22 Correct 155 ms 10588 KB Output is correct
23 Correct 164 ms 10616 KB Output is correct
24 Correct 214 ms 10780 KB Output is correct
25 Correct 200 ms 11000 KB Output is correct
26 Correct 156 ms 9472 KB Output is correct
27 Correct 145 ms 9032 KB Output is correct
28 Correct 212 ms 10436 KB Output is correct
29 Correct 174 ms 10744 KB Output is correct
30 Correct 97 ms 8572 KB Output is correct
31 Correct 185 ms 10856 KB Output is correct
32 Correct 169 ms 10360 KB Output is correct
33 Correct 187 ms 11000 KB Output is correct
34 Correct 190 ms 10724 KB Output is correct
35 Correct 146 ms 9316 KB Output is correct
36 Correct 48 ms 7544 KB Output is correct
37 Correct 199 ms 11640 KB Output is correct
38 Correct 193 ms 11092 KB Output is correct
39 Correct 206 ms 11384 KB Output is correct