답안 #599225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
599225 2022-07-19T11:45:51 Z Temmie 정렬하기 (IOI15_sorting) C++17
20 / 100
4 ms 3512 KB
#include <bits/stdc++.h>

int findSwapPairs(int n, int a[], int m, int u[], int v[], int uu[], int vv[]) {
	int l = 0, r = m, best = m;
	int inv[200'005];
	int u1[200'005];
	int v1[200'005];
	int b[200'005];
	while (l <= r) {
		int mid = (l + r) >> 1;
		for (int i = 0; i < n; i++) {
			b[i] = a[i];
		}
		for (int i = 0; i < mid; i++) {
			std::swap(a[u[i]], a[v[i]]);
		}
		for (int i = 0; i < n; i++) {
			inv[a[i]] = i;
		}
		int need = 0;
		memset(u1, 0, sizeof(u1));
		memset(v1, 0, sizeof(v1));
		for (int i = 0; i < n; i++) {
			if (a[i] == i) {
				continue;
			}
			int node = i;
			while (a[node] != node) {
				std::swap(a[node], a[inv[node]]);
				u1[need] = node;
				v1[need] = inv[node];
				need++;
				node = inv[node];
				int x = node;
				int y = inv[node];
				inv[a[x]] = x;
				inv[a[y]] = y;
			}
		}
		if (need <= mid) {
			for (int i = 0; i < mid; i++) {
				uu[i] = u1[i];
				vv[i] = v1[i];
			}
			best = mid;
			r = mid - 1;
		} else {
			l = mid + 1;
		}
		for (int i = 0; i < n; i++) {
			a[i] = b[i];
		}
	}
	return best;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 3 ms 3372 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3372 KB Output is correct
7 Correct 2 ms 3368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 3 ms 3372 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3372 KB Output is correct
7 Correct 2 ms 3368 KB Output is correct
8 Correct 2 ms 3412 KB Output is correct
9 Correct 2 ms 3412 KB Output is correct
10 Correct 2 ms 3380 KB Output is correct
11 Correct 2 ms 3412 KB Output is correct
12 Correct 2 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Incorrect 2 ms 3376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 3 ms 3372 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3372 KB Output is correct
7 Correct 2 ms 3368 KB Output is correct
8 Correct 2 ms 3412 KB Output is correct
9 Correct 2 ms 3412 KB Output is correct
10 Correct 2 ms 3380 KB Output is correct
11 Correct 2 ms 3412 KB Output is correct
12 Correct 2 ms 3412 KB Output is correct
13 Correct 2 ms 3412 KB Output is correct
14 Incorrect 2 ms 3376 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 3512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 3512 KB Output isn't correct
2 Halted 0 ms 0 KB -