답안 #973947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973947 2024-05-02T13:18:37 Z PagodePaiva 정렬하기 (IOI15_sorting) C++17
54 / 100
5 ms 604 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[]) {
    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;
}


Compilation message

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]);
      |          ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 600 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -