QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#130675 | #2789. Sorting | Qwerty1232# | 20 | 1ms | 4008kb | C++20 | 723b | 2023-07-24 19:36:09 | 2024-07-04 00:55:21 |
Judging History
answer
#include "sorting.h"
#include <bits/stdc++.h>
int findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
std::vector<std::pair<int, int>> ans;
std::vector<int> used(n);
for (int i = 0; i < n; i++) {
if (!used[i]) {
int u = i;
do {
int t = S[u];
used[u] = true;
if (t != i) {
ans.push_back({i, t});
}
u = t;
assert(ans.size() < M);
} while (u != i);
}
}
for (int i = 0; i < ans.size(); i++) {
P[i] = ans[i].first;
Q[i] = ans[i].second;
}
return ans.size();
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 8
Accepted
Test #1:
score: 8
Accepted
time: 0ms
memory: 3720kb
input:
1 0 1 0 0
output:
0
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
2 0 1 4 0 0 0 0 0 0 0 0
output:
0
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
2 1 0 4 0 0 0 0 0 0 0 0
output:
1 0 1
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3752kb
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: 0
Accepted
time: 0ms
memory: 4008kb
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 0 3 0 1 0 2
result:
ok correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 3984kb
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 0 1 0 4
result:
ok correct
Test #7:
score: 0
Accepted
time: 0ms
memory: 3728kb
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 0 4 0 3 1 2
result:
ok correct
Subtask #2:
score: 12
Accepted
Test #8:
score: 12
Accepted
time: 0ms
memory: 3724kb
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: 0
Accepted
time: 0ms
memory: 4008kb
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
Accepted
time: 0ms
memory: 3776kb
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:
93 0 82 0 41 0 20 0 34 0 61 0 29 0 48 0 18 0 63 0 5 0 51 0 59 0 3 0 12 0 74 0 43 0 73 0 95 0 81 0 60 0 17 0 67 0 30 0 2 0 31 0 55 0 40 0 72 0 64 0 21 0 50 0 71 0 80 0 22 0 87 0 10 0 49 0 11 0 52 0 88 0 47 0 28 0 77 0 23 0 83 0 69 0 92 0 1 0 70 0 45 0 93 0 6 0 84 4 27 4 39 4 86 4 14 4 46 4 65 4 15 4 ...
result:
ok correct
Test #11:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
99 8 14 3 0 98 74 18 10 50 93 49 23 80 2 54 79 90 31 66 38 81 36 42 83 39 7 9 71 59 62 67 4 68 5 70 72 34 95 25 27 45 61 97 48 29 15 46 12 87 22 26 63 77 84 11 85 30 24 40 78 41 1 96 69 94 19 6 65 33 13 52 75 88 82 86 20 92 43 89 47 28 73 35 32 53 60 21 16 37 58 44 76 57 56 17 55 91 51 64 2970 0 0 0...
output:
92 0 8 0 50 0 26 0 9 0 93 0 56 0 30 0 67 0 65 0 19 0 38 0 25 0 7 0 10 0 49 0 22 0 42 0 97 0 51 0 63 0 69 0 13 0 2 0 3 1 14 1 54 1 11 1 23 1 83 1 32 1 68 1 33 1 5 1 74 1 86 1 21 1 36 1 34 1 70 1 52 1 77 1 43 1 48 1 87 1 16 1 90 1 44 1 29 1 62 1 96 1 91 1 76 1 92 1 57 1 24 1 39 1 27 1 71 1 75 1 20 1 8...
result:
ok correct
Test #12:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
96 12 91 75 59 44 30 52 63 41 13 93 79 82 60 85 78 50 53 57 8 80 67 34 24 87 17 47 33 83 21 81 40 89 49 32 70 26 9 43 7 11 37 94 36 23 28 90 42 35 25 62 56 20 84 55 45 46 22 77 51 0 69 1 31 54 2 3 58 88 76 5 6 65 92 39 66 15 95 10 27 14 86 72 4 68 18 38 19 64 73 71 74 48 29 61 16 2880 0 0 0 0 0 0 0 ...
output:
95 0 12 0 82 0 72 0 65 0 2 0 75 0 66 0 3 0 59 0 51 0 56 0 46 0 90 0 71 0 6 0 52 0 20 0 80 0 14 0 85 0 18 0 57 0 22 0 34 0 32 0 89 0 73 0 92 0 48 0 35 0 70 0 5 0 30 0 81 0 86 0 38 0 43 0 36 0 26 0 47 0 42 0 94 0 61 0 69 0 76 0 15 0 78 0 10 0 93 0 29 0 21 0 67 0 58 0 77 0 95 0 16 0 50 0 62 0 1 0 91 0 ...
result:
ok correct
Subtask #3:
score: 0
Wrong Answer
Test #13:
score: 16
Accepted
time: 0ms
memory: 3780kb
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
Wrong Answer
time: 0ms
memory: 3728kb
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 1 4 1 2
result:
wrong answer the final array is not sorted
Subtask #4:
score: 0
Skipped
Dependency #2:
100%
Accepted
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #28:
score: 0
Wrong Answer
time: 1ms
memory: 3880kb
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:
1796 0 530 0 288 0 1704 0 346 0 1543 0 941 0 475 0 576 0 965 0 1091 0 194 0 1005 0 1734 0 1664 0 139 0 1736 0 1406 0 713 0 1157 0 1310 0 1342 0 1323 0 1671 0 1156 0 1727 0 486 0 633 0 323 0 1422 0 1183 0 1436 0 707 0 818 0 1680 0 722 0 384 0 666 0 939 0 831 0 1119 0 1690 0 729 0 786 0 1226 0 1311 0 ...
result:
wrong answer the final array is not sorted
Subtask #6:
score: 0
Skipped
Dependency #5:
0%