답안 #830422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
830422 2023-08-19T06:24:02 Z mindiyak 정렬하기 (IOI15_sorting) C++17
20 / 100
4 ms 340 KB
#include "sorting.h"
#include <queue>
#include <vector>
#include <iostream>
using namespace std;

void print(int N,int A[]){
	// for(int i=0;i<N;i++)cout << A[i] << " ";
	// cout << endl;
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    
	int R=0;
	int sorted = 0;

	for(int i=0;i<N;i++)if(S[i] == i)sorted++;

	print(N,S);

	// cout << sorted << endl;

	while(sorted<N){
		int dual = -1;
		int pos = -1;
		for(int i=0;i<N;i++){
			if(S[i] == i)continue;
			if(S[i] != i)pos = i;
			// cout << i << " " << S[i] << " " << S[S[i]] << endl;
			if(i == S[S[i]]){
				dual = 1;
				break;
			}
		}
		sorted += 1;
		P[R] = pos;
		Q[R] = S[pos];
		// cout << "swap " << dual << " " << P[R] <<  " " << Q[R] << endl;
		if(dual == 1){
			sorted += 1;
		}
		swap(S[P[R]],S[Q[R]]);
		R++;
		print(N,S);
	}

	return R;
}


Compilation message

sorting.cpp: In function 'void print(int, int*)':
sorting.cpp:7:16: warning: unused parameter 'N' [-Wunused-parameter]
    7 | void print(int N,int A[]){
      |            ~~~~^
sorting.cpp:7:22: warning: unused parameter 'A' [-Wunused-parameter]
    7 | void print(int N,int A[]){
      |                  ~~~~^~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:12:39: warning: unused parameter 'M' [-Wunused-parameter]
   12 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
sorting.cpp:12:46: warning: unused parameter 'X' [-Wunused-parameter]
   12 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                          ~~~~^~~
sorting.cpp:12:55: warning: unused parameter 'Y' [-Wunused-parameter]
   12 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                                   ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 1 ms 296 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Incorrect 0 ms 340 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -