Submission #414867

# Submission time Handle Problem Language Result Execution time Memory
414867 2021-05-31T09:47:26 Z Bill_00 Sorting (IOI15_sorting) C++14
100 / 100
164 ms 20396 KB
#include "sorting.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int ss[200005],xx[600005],yy[600005],pp[600005],qq[600005],o[200005],pos[200005];
bool check(int n,int array[]){
	for(int i=0;i<n;i++){
		if(i!=array[i]) return 0;
	}
	return 1;
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    int l=0,r=M;
    while(l<r){
    	for(int i=0;i<N;i++){
    		o[i]=S[i];
    	}
    	int m=(l+r)>>1,cnt=0;
    	for(int i=0;i<m;i++){
    		swap(o[X[i]],o[Y[i]]);
    	}
    	for(int i=0;i<N;i++){
    		pos[o[i]]=i;
    	}
    	for(int i=0;i<N;i++){
    		if(o[i]!=i){
    			pos[o[i]]=pos[i];
    			swap(o[i],o[pos[i]]);
    			pos[i]=i;
    			cnt++;
    		}
    	}
    	if(cnt<=m){
    		r=m;
    	}
    	else l=m+1;
    }
    for(int i=0;i<N;i++){
    	o[i]=S[i];
    }
    for(int i=0;i<l;i++){
    	swap(o[X[i]],o[Y[i]]);
    }
    for(int i=0;i<N;i++){
    	pos[o[i]]=i;
    }
    vector<pair<int,int> >operation;
    for(int i=0;i<N;i++){
    	if(o[i]!=i){
    		operation.pb({o[i],i});
    		pos[o[i]]=pos[i];
    		swap(o[i],o[pos[i]]);
    		pos[i]=i;
    	}
    }
    for(int i=0;i<N;i++){
    	pos[S[i]]=i;
    }
    for(int i=0;i<l;i++){
    	swap(pos[S[X[i]]],pos[S[Y[i]]]);
    	swap(S[X[i]],S[Y[i]]);
    	if(i>=operation.size()){
    		P[i]=pos[0];
    		Q[i]=pos[0];
    	}
    	else{
    		P[i]=pos[operation[i].first];
    		Q[i]=pos[operation[i].second];
    		swap(pos[S[P[i]]],pos[S[Q[i]]]);
    		swap(S[P[i]],S[Q[i]]);
    	}
    }
    return l;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:62:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |      if(i>=operation.size()){
      |         ~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 216 KB Output is correct
3 Correct 1 ms 216 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 216 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 216 KB Output is correct
3 Correct 1 ms 216 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 216 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 216 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 216 KB Output is correct
3 Correct 1 ms 216 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 216 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 216 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 216 KB Output is correct
19 Correct 1 ms 216 KB Output is correct
20 Correct 1 ms 216 KB Output is correct
21 Correct 2 ms 472 KB Output is correct
22 Correct 2 ms 448 KB Output is correct
23 Correct 2 ms 456 KB Output is correct
24 Correct 2 ms 472 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 472 KB Output is correct
27 Correct 2 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 472 KB Output is correct
2 Correct 2 ms 472 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 388 KB Output is correct
7 Correct 2 ms 472 KB Output is correct
8 Correct 2 ms 448 KB Output is correct
9 Correct 2 ms 472 KB Output is correct
10 Correct 2 ms 408 KB Output is correct
11 Correct 2 ms 452 KB Output is correct
12 Correct 2 ms 472 KB Output is correct
13 Correct 2 ms 472 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 472 KB Output is correct
2 Correct 2 ms 472 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 388 KB Output is correct
7 Correct 2 ms 472 KB Output is correct
8 Correct 2 ms 448 KB Output is correct
9 Correct 2 ms 472 KB Output is correct
10 Correct 2 ms 408 KB Output is correct
11 Correct 2 ms 452 KB Output is correct
12 Correct 2 ms 472 KB Output is correct
13 Correct 2 ms 472 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 137 ms 18056 KB Output is correct
16 Correct 142 ms 18368 KB Output is correct
17 Correct 160 ms 19528 KB Output is correct
18 Correct 71 ms 14800 KB Output is correct
19 Correct 128 ms 17668 KB Output is correct
20 Correct 128 ms 18344 KB Output is correct
21 Correct 134 ms 18384 KB Output is correct
22 Correct 117 ms 14732 KB Output is correct
23 Correct 145 ms 20212 KB Output is correct
24 Correct 163 ms 19904 KB Output is correct
25 Correct 160 ms 19664 KB Output is correct
26 Correct 133 ms 18360 KB Output is correct
27 Correct 122 ms 17632 KB Output is correct
28 Correct 156 ms 19588 KB Output is correct
29 Correct 152 ms 19100 KB Output is correct
30 Correct 102 ms 17080 KB Output is correct
31 Correct 155 ms 19576 KB Output is correct
32 Correct 149 ms 19460 KB Output is correct
33 Correct 161 ms 19864 KB Output is correct
34 Correct 151 ms 19724 KB Output is correct
35 Correct 127 ms 17600 KB Output is correct
36 Correct 70 ms 15892 KB Output is correct
37 Correct 163 ms 20396 KB Output is correct
38 Correct 157 ms 19488 KB Output is correct
39 Correct 164 ms 19728 KB Output is correct