답안 #832591

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832591 2023-08-21T12:06:38 Z aymanrs 정렬하기 (IOI15_sorting) C++14
36 / 100
54 ms 596 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, 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){
		R = 0;
		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(!f) 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 b;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:13:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 |   m = l+r>>1;
      |       ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 7 ms 332 KB Output is correct
11 Correct 7 ms 328 KB Output is correct
12 Correct 8 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 7 ms 212 KB Output is correct
4 Correct 7 ms 284 KB Output is correct
5 Correct 7 ms 332 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 7 ms 332 KB Output is correct
11 Correct 7 ms 328 KB Output is correct
12 Correct 8 ms 332 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 7 ms 212 KB Output is correct
16 Correct 7 ms 284 KB Output is correct
17 Correct 7 ms 332 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Runtime error 20 ms 596 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 54 ms 500 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 54 ms 500 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -