QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#234916 | #2789. Sorting | Camillus | 20 | 107ms | 4068kb | C++20 | 1.6kb | 2023-11-02 02:35:36 | 2023-11-02 02:35:36 |
Judging History
answer
#include "bits/stdc++.h"
#include "sorting.h"
using namespace std;
pair<int, int> any(int N, vector<int> S, int a, int b) {
vector<int> pos(N);
for (int i = 0; i < N; i++) {
pos[S[i]] = i;
}
for (int i = 0; i < N; i++) {
if (pos[i] != i) {
if (i != a && pos[i] != b && i != b && pos[i] != a) {
return {i, pos[i]};
}
}
}
return {0, 0};
}
int cost(int N, vector<int> s) {
vector<int> pos(N);
for (int i = 0; i < N; i++) {
pos[s[i]] = i;
}
int cnt = 0;
for (int i = 0; i < N; i++) {
if (pos[i] != i) {
cnt += 1;
int x = s[i];
int y = pos[i];
pos[x] = y;
pos[i] = i;
swap(s[i], s[y]);
}
}
return cnt;
}
int findSwapPairs(int N, int _S[], int M, int X[], int Y[], int P[], int Q[]) {
vector<int> S(_S, _S + N);
if (cost(N, S) == 0) {
return 0;
}
for (int i = 0; i < M; i++) {
swap(S[X[i]], S[Y[i]]);
int cur = cost(N, S);
if (cur == 0) {
P[i] = Q[i] = 0;
return i + 1;
}
if (cur == 1) {
vector<int> a;
for (int i = 0; i < N; i++) {
if (S[i] != i) {
a.push_back(i);
}
}
P[i] = a.front();
Q[i] = a.back();
return i + 1;
}
pair<int, int> best = {0, 0};
int val_bast = N;
for (int x = 0; x < N; x++) {
for (int y = x; y < N; y++) {
swap(S[x], S[y]);
swap(S[X[i + 1]], S[Y[i + 1]]);
if (cost(N, S) < val_bast) {
val_bast = cost(N, S);
best = {x, y};
}
swap(S[X[i + 1]], S[Y[i + 1]]);
swap(S[x], S[y]);
}
}
P[i] = best.first;
Q[i] = best.second;
swap(S[P[i]], S[Q[i]]);
}
return -1;
}
详细
Subtask #1:
score: 8
Accepted
Test #1:
score: 8
Accepted
time: 0ms
memory: 3760kb
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: 3796kb
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: 4068kb
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: 3700kb
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 1 0 2 1 3
result:
ok correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 4052kb
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: 3724kb
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 3 1 2 3 4
result:
ok correct
Subtask #2:
score: 12
Accepted
Test #8:
score: 12
Accepted
time: 0ms
memory: 4068kb
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: 3860kb
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: 107ms
memory: 4052kb
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 1 0 6 0 84 1 2 1 10 1 11 1 23 1 69 1 92 2 3 2 12 2 17 2 30 3 5 3 51 3 59 4 7 4 13 4 91 5 18 5 63 6 45 6 93 7 14 7 15 8 9 9 16 9 32 9 44 10 21 10 22 10 87 11 49 13 19 13 37 14 27 14 39 14 86 15 46 15 65 16 24 16 25 16 78 17 43 17 60 18 20 18 29 18 48 19 90 20 41 21 31 21 40 21 64 22 50 22 71 22 ...
result:
ok correct
Test #11:
score: 0
Accepted
time: 105ms
memory: 3792kb
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 2 0 3 1 5 1 16 1 20 1 35 1 37 1 41 1 61 2 7 2 10 2 13 4 17 4 31 5 11 5 23 5 32 5 33 6 18 6 66 7 8 7 9 7 19 7 25 9 26 11 14 11 54 12 15 12 47 13 22 13 42 13 51 13 63 13 69 15 28 15 40 15 45 16 21 16 34 16 43 16 48 16 87 17 64 17 94 19 30 19 65 20 24 20 27 20 71 20 75 21 74 21 86 22 49 24 29 24 5...
result:
ok correct
Test #12:
score: 0
Accepted
time: 105ms
memory: 3844kb
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 1 0 4 0 8 0 9 0 13 0 60 1 2 1 3 1 5 1 10 1 16 1 50 1 62 2 12 2 65 3 66 4 7 4 11 4 17 4 28 4 83 5 6 5 14 5 18 5 22 5 32 5 35 5 70 6 46 6 71 7 39 8 19 9 37 10 15 10 78 11 31 11 40 14 20 14 80 15 26 15 42 15 61 15 69 15 76 16 21 16 58 16 77 16 95 17 25 18 85 19 23 19 24 19 87 20 52 21 29 22 57 23 ...
result:
ok correct
Subtask #3:
score: 0
Time Limit Exceeded
Test #13:
score: 16
Accepted
time: 0ms
memory: 4052kb
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: 0
Accepted
time: 0ms
memory: 3760kb
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 0 2 2 4
result:
ok correct
Test #15:
score: -16
Time Limit Exceeded
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:
Unauthorized output
result:
Subtask #4:
score: 0
Skipped
Dependency #2:
100%
Accepted
Dependency #3:
0%
Subtask #5:
score: 0
Time Limit Exceeded
Test #28:
score: 0
Time Limit Exceeded
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%