답안 #973926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973926 2024-05-02T13:03:19 Z PagodePaiva 정렬하기 (IOI15_sorting) C++17
16 / 100
3 ms 600 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[]) {
    p[0] = 0;
	q[0] = 0;
	vector <int> v;
	for(int i = 0;i < n;i++){
		v.push_back(i);
	}
	for(int i = n-1;i >= 0;i--){
		swap(v[x[i]], v[y[i]]);
	}
	for(int i = 0;i < n;i++){
		// for(int j = 0;j < n;j++) {
		// 	cout << v[j] << ' ';
		// }
		// cout << '\n';
		swap(v[x[i]], v[y[i]]);
		swap(s[x[i]], s[y[i]]);
		int poss, posv;
		for(int j = 0;j < n;j++){
			if(s[j] == i) poss = j;
			if(v[j] == i) posv = j;
		}
		p[i] = poss;
		q[i] = posv;
		swap(s[poss], s[posv]);
	}
	// for(int j = 0;j < n;j++) cout << v[j] << ' ';
	// for(int j = 0;j < n;j++) cout << s[j] << ' ';
	return n;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:6:39: warning: unused parameter 'm' [-Wunused-parameter]
    6 | int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
      |                                   ~~~~^
sorting.cpp:30:19: warning: 'posv' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |   swap(s[poss], s[posv]);
      |                   ^~~~
sorting.cpp:30:10: warning: 'poss' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |   swap(s[poss], s[posv]);
      |          ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 440 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -