답안 #832684

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832684 2023-08-21T13:45:04 Z AkramElOmrani 정렬하기 (IOI15_sorting) C++17
54 / 100
238 ms 616 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;


int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
	int ans = 0;
	for(int round = 0; round < m; ++round) {
		if(is_sorted(s, s + n)) {
			return ans;
		}
		swap(s[x[round]], s[y[round]]);
		// we assume that after m rounds it will def be swapped
		vector<int> ord(n); iota(ord.begin(), ord.end(), 0);
		// ord[i] = i; at last since it's sorted
		for(int j = m - 1; j > round; --j) {
			swap(ord[x[j]], ord[y[j]]);
		}
		vector<int> inv_s(n);
		for(int i = 0; i < n; ++i) {
			inv_s[s[i]] = i;
		}
		for(int i = 0; i < n; ++i) {
			if(s[i] != ord[i]) {
				int k = inv_s[ord[i]];
				swap(s[k], s[i]);
				p[ans] = k;
				q[ans] = i;
				goto end;
			}
		}
		// for(int i = 0; i < n; ++i) {
		// 	if(s[i] != ord[i]) { // ith element isn't in its place look for who is in its place
		// 		for(int k = i + 1; k < n; ++k) {
		// 			if(s[k] == ord[i]) {
		// 				swap(s[k], s[i]);
		// 				p[ans] = k;
		// 				q[ans] = i;
		// 				goto end;
		// 			}
		// 		}
		// 	}
		// }
		p[ans] = q[ans] = n - 1; // already sorted no change needed
		end:;
		++ans;
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 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 212 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 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 216 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 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 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 216 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 137 ms 616 KB Output is correct
22 Correct 134 ms 564 KB Output is correct
23 Correct 146 ms 588 KB Output is correct
24 Correct 138 ms 544 KB Output is correct
25 Correct 144 ms 544 KB Output is correct
26 Correct 141 ms 580 KB Output is correct
27 Correct 238 ms 548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -