Submission #335158

# Submission time Handle Problem Language Result Execution time Memory
335158 2020-12-11T10:03:04 Z kshitij_sodani Sorting (IOI15_sorting) C++14
0 / 100
19 ms 492 KB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
//#define endl '\n'

#include "sorting.h"
int cur[200001];
int findSwapPairs(int n, int aa[], int m, int x[], int y[], int p[], int q[]){
	int stt=1;

	for(int i=0;i<n;i++){
		cur[i]=i;
		if(aa[i]!=i){
			stt=0;
		}
	}
	if(stt==1){
		return 0;
	}
	for(int i=m-1;i>=0;i--){
		swap(cur[x[i]],cur[y[i]]);
	}
	vector<int> bb;
	for(int i=0;i<n;i++){
		bb.pb(aa[i]);
	}
	for(int i=0;i<m;i++){
		swap(cur[x[i]],cur[y[i]]);
		swap(aa[x[i]],aa[y[i]]);
		int ind=-1;
		p[i]=0;
		q[i]=0;
		int st=1;
		for(int j=0;j<n;j++){
			if(aa[j]!=j){
				st=0;
			}
		}
		if(st==1){
			if(i<m-1){
				p[i]=0;
				q[i]=1;
			}
			swap(cur[p[i]],cur[q[i]]);
			continue;
		}
		for(int j=0;j<n;j++){
			if(aa[j]!=cur[j]){
				ind=j;
				break;
			}
		}

		if(ind==-1){
			continue;
		}
		int ind2=-1;
		for(int j=0;j<n;j++){
			if(cur[j]==aa[ind]){
				ind2=j;
			}
		}
		p[i]=ind;
		q[i]=ind2;

		swap(aa[p[i]],aa[q[i]]);
	}
	for(int i=0;i<m;i++){
		swap(bb[x[i]],bb[y[i]]);
		swap(bb[p[i]],bb[q[i]]);
	}
/*	for(int i=0;i<n;i++){
		cout<<bb[i]<<":";
	}
	cout<<endl;

*/
















	return m;
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -