답안 #1004604

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1004604 2024-06-21T10:25:45 Z phoenix 정렬하기 (IOI15_sorting) C++17
74 / 100
1000 ms 16172 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[]) {
	vector<pair<int, int>> res;
	
	function<bool(int)> check = [&](int len) -> bool {
		res.resize(len);
		vector<int> s(n), pos(n);
		for (int i = 0; i < n; i++) {
			s[i] = S[i];
			pos[S[i]] = i;
		}

		vector<int> p(n), q(n);
		iota(p.begin(), p.end(), 0);
		iota(q.begin(), q.end(), 0);
		auto do_swap = [&](int i, int j) {
			swap(p[i], p[j]);
			swap(q[p[i]], q[p[j]]);
		};
		for (int i = len - 1; i >= 0; i--) {
			do_swap(X[i], Y[i]);
		}

		int l = n - 1;
		for (int i = 0; i < len; i++) {
			do_swap(X[i], Y[i]);
			swap(s[X[i]], s[Y[i]]);
			swap(pos[s[X[i]]], pos[s[Y[i]]]);

			while (l >= 0 && q[l] == pos[l]) 
				l--;
			if (l == -1) 
				res[i] = {0, 0};
			else {
				res[i] = {pos[l], q[l]};
			}
			swap(s[res[i].first], s[res[i].second]);
			swap(pos[s[res[i].first]], pos[s[res[i].second]]);
		}
		while (l >= 0 && q[l] == pos[l]) l--;
		return (l == -1);
	};

	for (int len = 0; len <= m; len++) {
		if (check(len)) {
			for (int i = 0; i < len; i++) {
				P[i] = res[i].first;
				Q[i] = res[i].second;
			}
			return len;
		}
	}

	return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 344 KB Output is correct
7 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 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 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 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 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 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 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 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 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 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 356 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 3 ms 568 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 604 KB Output is correct
2 Correct 31 ms 604 KB Output is correct
3 Correct 22 ms 600 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
5 Correct 1 ms 516 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 10 ms 604 KB Output is correct
8 Correct 23 ms 604 KB Output is correct
9 Correct 29 ms 604 KB Output is correct
10 Correct 24 ms 596 KB Output is correct
11 Correct 21 ms 604 KB Output is correct
12 Correct 11 ms 612 KB Output is correct
13 Correct 29 ms 600 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 604 KB Output is correct
2 Correct 31 ms 604 KB Output is correct
3 Correct 22 ms 600 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
5 Correct 1 ms 516 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 10 ms 604 KB Output is correct
8 Correct 23 ms 604 KB Output is correct
9 Correct 29 ms 604 KB Output is correct
10 Correct 24 ms 596 KB Output is correct
11 Correct 21 ms 604 KB Output is correct
12 Correct 11 ms 612 KB Output is correct
13 Correct 29 ms 600 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Execution timed out 1049 ms 16172 KB Time limit exceeded
16 Halted 0 ms 0 KB -