답안 #155927

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155927 2019-10-02T04:51:11 Z junodeveloper 정렬하기 (IOI15_sorting) C++14
100 / 100
508 ms 22904 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
int n,m,*x,*y,*s,*p,*q;
int a[500010],b[500010],c[500010],d[500010];
bool f(int z) {
	int i,j;
	for(i=0;i<n;i++) {
		a[i]=b[i]=s[i];
	}
	for(i=0;i<z;i++) {
		swap(a[x[i]],a[y[i]]);
	}
	for(i=0;i<n;i++) {
		c[a[i]]=i;
		d[b[i]]=i;
	}
	j=0;
	for(i=0;i<z;i++) {
		swap(d[b[x[i]]],d[b[y[i]]]);
		swap(b[x[i]],b[y[i]]);
		while(j<n&&a[j]==j)j++;
		if(j==n)p[i]=q[i]=0;
		else {
			p[i]=d[j],q[i]=d[a[j]];
			swap(b[d[j]],b[d[a[j]]]);
			swap(d[j],d[a[j]]);
			c[a[j]]=c[j];
			swap(a[j],a[c[j]]);
			c[j]=j;
		}
	}
	for(i=0;i+1<n;i++) if(a[i]>a[i+1]) return false;
	return true;
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	n=N;s=S;m=M;x=X;y=Y;p=P;q=Q;
	int lo=0,hi=M;
	while(lo<hi) {
		int mid=(lo+hi)/2;
		if(f(mid))hi=mid;
		else lo=mid+1;
	}
	f(lo);
	return lo;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 380 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 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 380 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 380 KB Output is correct
7 Correct 2 ms 376 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 476 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 380 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 380 KB Output is correct
7 Correct 2 ms 376 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 504 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 476 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 504 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 632 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 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 3 ms 508 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 4 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 4 ms 500 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 3 ms 508 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 4 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 4 ms 500 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 273 ms 20076 KB Output is correct
16 Correct 320 ms 20600 KB Output is correct
17 Correct 419 ms 21624 KB Output is correct
18 Correct 128 ms 18552 KB Output is correct
19 Correct 307 ms 20856 KB Output is correct
20 Correct 328 ms 21496 KB Output is correct
21 Correct 334 ms 21496 KB Output is correct
22 Correct 262 ms 16960 KB Output is correct
23 Correct 288 ms 22540 KB Output is correct
24 Correct 450 ms 22108 KB Output is correct
25 Correct 420 ms 21752 KB Output is correct
26 Correct 299 ms 21468 KB Output is correct
27 Correct 272 ms 20856 KB Output is correct
28 Correct 405 ms 22136 KB Output is correct
29 Correct 381 ms 21724 KB Output is correct
30 Correct 228 ms 20472 KB Output is correct
31 Correct 380 ms 22136 KB Output is correct
32 Correct 299 ms 21816 KB Output is correct
33 Correct 407 ms 22120 KB Output is correct
34 Correct 379 ms 22056 KB Output is correct
35 Correct 303 ms 20572 KB Output is correct
36 Correct 91 ms 19876 KB Output is correct
37 Correct 508 ms 22904 KB Output is correct
38 Correct 462 ms 21880 KB Output is correct
39 Correct 469 ms 22008 KB Output is correct