Submission #1098436

# Submission time Handle Problem Language Result Execution time Memory
1098436 2024-10-09T11:41:01 Z alexander707070 Sorting (IOI15_sorting) C++14
0 / 100
1000 ms 604 KB
#include<bits/stdc++.h>
#include "sorting.h"

#define MAXN 200007
using namespace std;

int n,m,q,br;
int pos[MAXN],s[MAXN],post[MAXN];

int to[MAXN];

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    n=N; m=M;

	for(int stop=n;stop<=n;stop++){

		for(int i=0;i<n;i++)s[i]=i;
		for(int i=0;i<stop;i++)swap(s[X[i]],s[Y[i]]);

		for(int i=0;i<n;i++)to[s[i]]=i;
		for(int i=0;i<n;i++){
			s[i]=S[i]; pos[s[i]]=i;
			post[to[i]]=i;
		}

		int pt=0;
		for(int i=0;i<stop;i++){
			P[i]=Q[i]=0;

			swap(s[X[i]],s[Y[i]]);
			swap(to[X[i]],to[Y[i]]);

			swap(pos[s[X[i]]],pos[s[Y[i]]]);
			swap(post[to[X[i]]],post[to[Y[i]]]);

			while(pt<n and to[pos[pt]]==pt)pt++;
			if(pt==n)continue;

			P[i]=pos[pt]; Q[i]=post[to[pt]];

			swap(s[P[i]],s[Q[i]]);
			swap(pos[s[P[i]]],pos[s[Q[i]]]);
		}

		q=stop; br=0;
		for(int i=0;i<n;i++){
			if(s[i]==i)br++;
			s[i]=S[i];
		}

		for(int i=0;i<stop;i++){
			if(br==n)return i;

			if(s[X[i]]==X[i])br--;
			if(s[Y[i]]==Y[i])br--;

			swap(s[X[i]],s[Y[i]]);

			if(s[X[i]]==X[i])br++;
			if(s[Y[i]]==Y[i])br++;

			if(s[P[i]]==P[i])br--;
			if(s[Q[i]]==Q[i])br--;
			
			swap(s[P[i]],s[Q[i]]);

			if(s[P[i]]==P[i])br++;
			if(s[Q[i]]==Q[i])br++;
		}

		if(br==n)return q;
	}
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:73:1: warning: control reaches end of non-void function [-Wreturn-type]
   73 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1052 ms 604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1052 ms 604 KB Time limit exceeded
2 Halted 0 ms 0 KB -