Submission #832586

# Submission time Handle Problem Language Result Execution time Memory
832586 2023-08-21T12:04:39 Z aymanrs Sorting (IOI15_sorting) C++14
0 / 100
19 ms 504 KB
#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	if(is_sorted(S, S+N)) return 0;
	int p[N], q[N];
	int R = 0, l = 0, r = M-1, m, b = M;
	int cp[N];
	for(int i = 0;i < N;i++) cp[i] = S[i];
	while(l <= r){
		for(int i = 0;i < N;i++) S[i] = cp[i];
		m = l+r>>1;
		for(int i = 0;i <= m;i++){
			if(is_sorted(S, S+N)) break;
			R++;
			swap(S[X[i]], S[Y[i]]);
			int opt[N];
			for(int j = 0;j<N;j++) opt[j]=j;
			for(int j = M-1;j > i;j--) swap(opt[X[j]], opt[Y[j]]);
			bool f = false;
			for(int j = 0;j < N;j++){
				if(S[j] != opt[j]){
					f = true;
					for(int k = j+1;k < N;k++) {
						if(S[k] == opt[j]) {
							p[R-1] = j;
							q[R-1] = k;
							swap(S[j], S[k]);
							break;
						}
					}
					break;
				}
			}
			if(!i) p[R-1] = q[R-1] = 0;
		}
		if(is_sorted(S, S+N)){
			for(int i = 0;i < R;i++) {
				P[i] = p[i];
				Q[i] = q[i];
			}
			b = R;
			r = m-1;
		} else l = m+1;
	}
	return R;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:12:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   12 |   m = l+r>>1;
      |       ~^~
sorting.cpp:20:9: warning: variable 'f' set but not used [-Wunused-but-set-variable]
   20 |    bool f = false;
      |         ^
sorting.cpp:7:32: warning: variable 'b' set but not used [-Wunused-but-set-variable]
    7 |  int R = 0, l = 0, r = M-1, m, b = M;
      |                                ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 19 ms 504 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 19 ms 504 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -