Submission #128058

# Submission time Handle Problem Language Result Execution time Memory
128058 2019-07-10T11:28:07 Z ekrem Sorting (IOI15_sorting) C++
100 / 100
573 ms 29816 KB
#include "sorting.h"
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define EKLE 1
#define mod 1000000007
#define inf 1000000009
#define MAXN 1000005
using namespace std;
 
typedef long long ll;
typedef pair < int , int > ii;
 
int n, m, f, a[MAXN], b[MAXN], x[MAXN], y[MAXN], yer[MAXN], p[MAXN], q[MAXN], s[MAXN], yerb[MAXN];
 
bool dene(int son){
 
	for(int i = 1; i <= n; i++)a[i] = s[i];
 
	for(int i = 1; i <= n; i++)
		b[i] = i;
 
	for(int i = son; i >= 1; i--)
		swap(b[x[i]], b[y[i]]);
 
	for(int i = 1; i <= n; i++){
		yer[a[i]] = i;
		yerb[b[i]] = i;
	}
 
	int su = 1;
	for(int i = 1; i <= son; i++){
		swap(a[x[i]], a[y[i]]);
		swap(yer[a[x[i]]], yer[a[y[i]]]);
		swap(b[x[i]], b[y[i]]);
		swap(yerb[b[x[i]]], yerb[b[y[i]]]);
		// cout << i << " ->\n";
		// for(int i = 1; i <= n; i++)cout << a[i] << " ";cout << endl;
		// for(int i = 1; i <= n; i++)cout << b[i] << " ";cout << endl;
		while(su <= n and yer[su] == yerb[su])
			su++;
		if(su > n){
			p[i] = q[i] = 1;
			continue;
		}
		int j = yerb[su];
		p[i] = j;
		q[i] = yer[b[j]];
		swap(a[p[i]], a[q[i]]);
		swap(yer[a[p[i]]], yer[a[q[i]]]);
		su++;
 
	}
	// cout << son << " -> ";for(int i = 1; i <= n; i++)cout << a[i] << " ";cout << endl;
	for(int i = 1; i <= n; i++)
		if(a[i] != i)
			return 0;
	return 1;
}
 
int findSwapPairs(int nn, int S[], int M, int X[], int Y[], int P[], int Q[]) {n = nn;m = M;
	for(int i = 1; i <= n; i++){
		s[i] = a[i] = S[i - 1] + EKLE;
		if(a[i] != i)
			f = 1;
	}
	if(!f)return 0;
	for(int i = 1; i <= m; i++){
		x[i] = X[i - 1] + EKLE;
		y[i] = Y[i - 1] + EKLE;
	}
	int bas = 1, son = m;
	while(bas < son){
		if(dene(orta))
			son = orta;
		else
			bas = orta + 1;
	}
	dene(orta);
 
	for(int i = 1; i <= orta; i++){
		P[i - 1] = p[i] - EKLE;
		Q[i - 1] = q[i] - EKLE;
	}
	return orta;
}





# 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 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 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 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 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 3 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 476 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 3 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 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 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 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 3 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 476 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 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 760 KB Output is correct
22 Correct 3 ms 760 KB Output is correct
23 Correct 3 ms 632 KB Output is correct
24 Correct 3 ms 760 KB Output is correct
25 Correct 3 ms 760 KB Output is correct
26 Correct 3 ms 760 KB Output is correct
27 Correct 3 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 4 ms 632 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 4 ms 504 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Correct 4 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 4 ms 632 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 4 ms 632 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 4 ms 504 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Correct 4 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 4 ms 632 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 360 ms 18624 KB Output is correct
16 Correct 410 ms 26872 KB Output is correct
17 Correct 483 ms 28408 KB Output is correct
18 Correct 44 ms 14968 KB Output is correct
19 Correct 328 ms 27000 KB Output is correct
20 Correct 345 ms 27768 KB Output is correct
21 Correct 360 ms 27808 KB Output is correct
22 Correct 365 ms 23928 KB Output is correct
23 Correct 375 ms 29432 KB Output is correct
24 Correct 512 ms 28964 KB Output is correct
25 Correct 505 ms 28664 KB Output is correct
26 Correct 331 ms 27768 KB Output is correct
27 Correct 299 ms 26976 KB Output is correct
28 Correct 483 ms 28892 KB Output is correct
29 Correct 456 ms 28280 KB Output is correct
30 Correct 233 ms 26360 KB Output is correct
31 Correct 475 ms 28792 KB Output is correct
32 Correct 383 ms 28408 KB Output is correct
33 Correct 510 ms 29048 KB Output is correct
34 Correct 458 ms 28920 KB Output is correct
35 Correct 344 ms 26588 KB Output is correct
36 Correct 95 ms 25336 KB Output is correct
37 Correct 573 ms 29816 KB Output is correct
38 Correct 545 ms 28668 KB Output is correct
39 Correct 524 ms 28792 KB Output is correct