QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#124437#2789. Sortingvalerikk#8 1ms3888kbC++171.7kb2023-07-14 19:52:152024-07-04 00:40:37

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 00:40:37]
  • 评测
  • 测评结果:8
  • 用时:1ms
  • 内存:3888kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-14 19:52:15]
  • 提交

answer

#include "sorting.h"
#include <bits/stdc++.h>

using namespace std;

namespace {

const int N = 2005;

int n, s[N];
int m, x[N], y[N];
int ansp[N], ansq[N];
int ansr;
int curs[N], s1[N];
bool used[N];

}

int findSwapPairs(int grdn, int grds[], int grdm, int grdx[], int grdy[], int grdp[], int grdq[]) {
	n = grdn;
	for (int i = 0; i < n; ++i) {
		s[i] = grds[i];
	}
	m = grdm;
	for (int i = 0; i < m; ++i) {
		x[i] = grdx[i];
		y[i] = grdy[i];
	}
	for (int i = 0; i < n; ++i) {
		curs[i] = s[i];
	}
	for (int r = 0; r <= m; ++r) {
		vector<vector<int>> kek;
		for (int i = 0; i < n; ++i) {
			used[i] = 0;
		}
		for (int i = 0; i < n; ++i) {
			if (!used[i]) {
				int v = i;
				vector<int> lol;
				while (!used[v]) {
					used[v] = 1;
					lol.push_back(v);
					v = curs[v];
				}
				kek.push_back(lol);
			}
		}
		if (r >= n - (int)kek.size()) {
			ansr = r;
			for (int i = 0; i < n; ++i) {
				s1[i] = curs[i];
			}
			vector<pair<int, int>> swaps;
			for (auto lol : kek) {
				for (int i = 1; i < (int)lol.size(); ++i) {
					swaps.push_back({s1[lol[0]], s1[lol[i]]});
					swap(s1[lol[0]], s1[lol[i]]);
				}
			}
			while ((int)swaps.size() < r) {
				swaps.push_back({0, 0});
			}
			assert((int)swaps.size() == r);
			for (int i = 0; i < n; ++i) {
				s1[i] = curs[i];
			}
			for (int i = r - 1; i >= 0; --i) {
				int x1 = swaps[r - i - 1].first;
				int y1 = swaps[r - i - 1].second;
				int px1 = 0;
				while (s1[px1] != x1) {
					++px1;
				}
				int py1 = 0;
				while (s1[py1] != y1) {
					++py1;
				}
				ansp[i] = px1;
				ansq[i] = py1;
				swap(s1[x[i]], s1[y[i]]);
			}
			break;
		}
		if (r < m) {
			swap(curs[x[r]], curs[y[r]]);
		}
	}
	for (int i = 0; i < ansr; ++i) {
		grdp[i] = ansp[i];
		grdq[i] = ansq[i];
	}
	return ansr;
}



詳細信息

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 0ms
memory: 3672kb

input:

1
0
1
0 0

output:

0

result:

ok correct

Test #2:

score: 8
Accepted
time: 1ms
memory: 3888kb

input:

2
0 1
4
0 0
0 0
0 0
0 0

output:

0

result:

ok correct

Test #3:

score: 8
Accepted
time: 0ms
memory: 3676kb

input:

2
1 0
4
0 0
0 0
0 0
0 0

output:

1
0 1

result:

ok correct

Test #4:

score: 8
Accepted
time: 0ms
memory: 3740kb

input:

3
1 0 2
9
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

1
0 1

result:

ok correct

Test #5:

score: 8
Accepted
time: 1ms
memory: 3792kb

input:

4
3 2 0 1
16
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

3
1 2
3 1
0 3

result:

ok correct

Test #6:

score: 8
Accepted
time: 0ms
memory: 3792kb

input:

5
1 4 2 3 0
25
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

2
1 4
0 1

result:

ok correct

Test #7:

score: 8
Accepted
time: 0ms
memory: 3788kb

input:

5
4 2 1 0 3
25
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

3
1 2
4 3
0 4

result:

ok correct

Subtask #2:

score: 0
Wrong Answer

Test #8:

score: 12
Accepted
time: 1ms
memory: 3688kb

input:

1
0
30
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

0

result:

ok correct

Test #9:

score: 12
Accepted
time: 1ms
memory: 3728kb

input:

2
0 1
60
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

0

result:

ok correct

Test #10:

score: 0
Wrong Answer
time: 0ms
memory: 3716kb

input:

98
82 70 31 12 27 51 84 90 66 8 49 52 74 91 46 7 96 67 63 85 34 50 87 83 58 78 26 39 77 48 2 55 94 25 61 56 53 13 32 86 72 20 37 73 9 93 65 28 18 11 71 59 88 35 76 40 24 36 33 3 17 29 38 5 21 15 79 30 62 92 45 80 64 95 43 75 97 23 16 57 22 60 41 69 0 42 14 10 47 68 19 4 1 6 44 81 54 89
2940
0 0
0 0
...

output:

0

result:

wrong answer the final array is not sorted

Subtask #3:

score: 0
Wrong Answer

Test #13:

score: 16
Accepted
time: 0ms
memory: 3884kb

input:

2
0 1
60
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1

output:

0

result:

ok correct

Test #14:

score: 16
Accepted
time: 0ms
memory: 3804kb

input:

5
0 4 1 3 2
150
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
...

output:

2
4 2
1 4

result:

ok correct

Test #15:

score: 0
Wrong Answer
time: 1ms
memory: 3716kb

input:

96
7 15 12 95 11 50 20 42 81 29 58 80 56 71 63 66 44 6 64 39 2 22 73 1 24 27 69 28 45 25 60 61 5 94 14 65 9 86 68 32 79 37 3 57 34 35 10 88 76 78 21 93 19 53 84 52 4 33 38 55 62 67 77 41 31 48 91 49 51 43 90 8 87 54 16 17 70 46 85 0 75 92 74 47 36 89 30 13 59 26 40 18 82 83 72 23
2880
0 1
0 1
0 1
0 ...

output:

0

result:

wrong answer the final array is not sorted

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Runtime Error

Test #28:

score: 0
Runtime Error

input:

1800
530 1775 466 953 230 1179 944 752 990 1316 275 1029 158 152 1673 1706 172 115 599 1661 131 699 1112 454 551 1059 291 495 28 67 773 480 839 462 1210 757 879 285 439 3 1429 820 26 1023 942 199 356 625 1705 1421 144 1529 716 7 1485 1027 1599 696 517 1353 456 1389 273 1363 1414 1177 718 41 777 1621...

output:

Unauthorized output

result:


Subtask #6:

score: 0
Skipped

Dependency #5:

0%