Submission #335167

# Submission time Handle Problem Language Result Execution time Memory
335167 2020-12-11T10:34:12 Z kshitij_sodani Sorting (IOI15_sorting) C++14
20 / 100
85 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(aa[x[i]],aa[y[i]]);
		

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

		for(int j=i+1;j<m;j++){
			swap(cur[x[j]],cur[y[j]]);
		}
		for(int j=0;j<n;j++){
			if(aa[j]!=cur[j]){
				ind=j;
				break;
			}
		}
		if(ind==-1){
			if(true){
				int st=1;
				for(int j=0;j<n;j++){
					if(aa[j]!=j){
						st=0;
					}
				}
				if(st==1){
					return i+1;
				}
			}
			continue;
		}
		int ind2=-1;
		for(int j=0;j<n;j++){
			if(cur[j]==aa[ind]){
				ind2=j;
			}
		}
		p[i]=ind;
		if(ind2==-1){
			while(true){
				continue;
			}
		}
		q[i]=ind2;
		swap(aa[p[i]],aa[q[i]]);
		if(true){
			int st=1;
			for(int j=0;j<n;j++){
				if(aa[j]!=j){
					st=0;
				}
			}
			if(st==1){
				return i+1;
			}
		}
		
	}

	/*for(int i=0;i<n;i++){
		if(bb[i]!=i){
			while(true){
				continue;
			}
		}
	}*/
/*	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 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
# 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 2 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 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Incorrect 2 ms 364 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 85 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 85 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -