제출 #973947

#제출 시각아이디문제언어결과실행 시간메모리
973947PagodePaiva정렬하기 (IOI15_sorting)C++17
54 / 100
5 ms604 KiB
#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[]) {
    for(int i = 0;i < m;i++) p[i] = q[i] = 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]]);
	}
	int res = 0;
	for(int i = 0;i < n;i++){
		// for(int j = 0;j < n;j++) {
		// 	cout << v[j] << ' ';
		// }
		// cout << '\n';
		bool aux = true;
		for(int j = 1;j < n;j++){
			if(s[j] < s[j-1]) aux = false;
		}
		if(aux) break;
		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]);
		res++;
	}
	// for(int j = 0;j < n;j++) cout << v[j] << ' ';
		// cout << "\n";
	// for(int j = 0;j < n;j++) cout << s[j] << ' ';
	return res;
}


컴파일 시 표준 에러 (stderr) 메시지

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:35:19: warning: 'posv' may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |   swap(s[poss], s[posv]);
      |                   ^~~~
sorting.cpp:35:10: warning: 'poss' may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |   swap(s[poss], s[posv]);
      |          ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...