답안 #426067

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
426067 2021-06-13T13:36:15 Z _fractal 정렬하기 (IOI15_sorting) C++14
0 / 100
1000 ms 380 KB
#include "sorting.h"
#include <iostream>
#include <algorithm>
using namespace std;
 
 
int findSwapPairs(int N, int SS[], int M, int X[], int Y[], int P[], int Q[]) {
	int A[N], pos[N], S[N], L[M], R[M];
	int tl = 0, tr = M - 1, ret = (1<<30);
	for (int tm = 0; tm < M; ++tm) {
		for (int i = 0; i < N; ++i)
			A[i] = i, S[i] = SS[i];
		for (int i = tm; i >= 0; --i)
			swap(A[X[i]], A[Y[i]]);
		int ans = -1;
		for (int i = 0; i <= tm; ++i) {
			P[i] = Q[i] = 0;
			bool f = 1;
			swap(S[X[i]], S[Y[i]]);
			swap(A[X[i]], A[Y[i]]);
			for (int j = 0; j < N; ++j)
				pos[A[j]] = j;
			for (int j = 0; j < N; ++j)
				pos[A[j]] = j;
			for (int j = 0; j < N; ++j) {
				if (pos[S[j]] != j) {
					Q[i] = j, P[i] = pos[S[j]];
					break;
				}
			}
			swap(S[Q[i]], S[P[i]]);
		}
		bool f = 1;
		for (int i = 1; i < N; ++i)
			if (S[i - 1] > S[i])
				f = 0;
		if (f == 0)
			continue;
		if (ans != -1) ans = tm;
		if (ret > ans) {
			ret = ans;
			for (int i = 0; i < ret; ++i)
				L[i] = Q[i], R[i] = P[i];
		}
	}
	for (int i = 0; i < ret; i++)
		Q[i] = L[i], P[i] = R[i];
	return ret;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:18:9: warning: unused variable 'f' [-Wunused-variable]
   18 |    bool f = 1;
      |         ^
sorting.cpp:9:6: warning: unused variable 'tl' [-Wunused-variable]
    9 |  int tl = 0, tr = M - 1, ret = (1<<30);
      |      ^~
sorting.cpp:9:14: warning: unused variable 'tr' [-Wunused-variable]
    9 |  int tl = 0, tr = M - 1, ret = (1<<30);
      |              ^~
# 결과 실행 시간 메모리 Grader output
1 Failed 1 ms 204 KB MODEL SOLUTION IS WRONG
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 1 ms 204 KB MODEL SOLUTION IS WRONG
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 1 ms 204 KB MODEL SOLUTION IS WRONG
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 1 ms 204 KB MODEL SOLUTION IS WRONG
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1095 ms 380 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1095 ms 380 KB Time limit exceeded
2 Halted 0 ms 0 KB -