QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#130695#2789. SortingQwerty1232#8 979ms4060kbC++202.5kb2023-07-24 19:51:492024-07-04 00:55:27

Judging History

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

  • [2024-07-04 00:55:27]
  • 评测
  • 测评结果:8
  • 用时:979ms
  • 内存:4060kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-24 19:51:49]
  • 提交

answer

#include "sorting.h"

#include <bits/stdc++.h>

int findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    if (0 && std::all_of(X, X + M, [&](int a) { return a == 0; }) && std::all_of(Y, Y + M, [&](int a) { return a == 0; })) {
        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();
    }

    auto cum = [&](std::vector<std::pair<int, int>> ans) {
        int m = ans.size();
        std::vector<int> p(S, S + n);
        for (int i = 0; i < m; i++) {
            std::swap(p[X[i]], p[Y[i]]);
            std::swap(p[ans[i].first], p[ans[i].second]);
        }
        std::vector<bool> used(n);
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (!used[i]) {
                int u = i;
                do {
                    used[u] = true;
                    u = p[u];
                } while (u != i);
                cnt++;
            }
        }
        return cnt;
    };

    static std::mt19937 rnd;

    for (int iter = 0;; iter++) {
        int m = std::min(M, 4 * n);
        std::vector<std::pair<int, int>> ans(m);
        for (int i = 0; i < m; i++) {
            ans[i] = {rnd() % n, rnd() % n};
        }
        int sc = cum(ans);
        // while (sc < n) {
        for (int f = 0; f < 1e6; f++) {
            int i = rnd() % m;
            std::pair<int, int> pr = {rnd() % n, rnd() % n};
            std::swap(ans[i], pr);
            int sc2 = cum(ans);
            if (sc2 >= sc) {
                if (sc2 > sc) {
                    std::cerr << sc2 << "\n";
                }
                sc = sc2;
            } else {
                std::swap(ans[i], pr);
            }
        }

        if (sc == n) {
            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: 49ms
memory: 3988kb

input:

1
0
1
0 0

output:

1
0 0

result:

ok correct

Test #2:

score: 0
Accepted
time: 67ms
memory: 3712kb

input:

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

output:

4
0 0
0 1
1 0
1 1

result:

ok correct

Test #3:

score: 0
Accepted
time: 68ms
memory: 3736kb

input:

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

output:

4
0 0
0 1
1 1
1 1

result:

ok correct

Test #4:

score: 0
Accepted
time: 80ms
memory: 3708kb

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:

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

result:

ok correct

Test #5:

score: 0
Accepted
time: 112ms
memory: 3704kb

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:

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

result:

ok correct

Test #6:

score: 0
Accepted
time: 118ms
memory: 4060kb

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:

20
2 1
4 0
1 4
4 0
1 1
3 3
1 0
0 4
3 3
1 2
2 2
4 3
4 4
1 3
0 1
2 4
3 4
1 0
4 4
3 2

result:

ok correct

Test #7:

score: 0
Accepted
time: 118ms
memory: 3784kb

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:

20
2 2
4 0
1 4
4 0
1 1
3 3
2 1
0 4
3 3
1 2
2 2
4 3
2 0
1 3
1 4
2 4
3 4
1 0
4 4
3 3

result:

ok correct

Subtask #2:

score: 0
Time Limit Exceeded

Test #8:

score: 12
Accepted
time: 62ms
memory: 3736kb

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:

4
0 0
0 0
0 0
0 0

result:

ok correct

Test #9:

score: 0
Accepted
time: 75ms
memory: 3784kb

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:

8
1 1
1 0
0 1
0 0
1 0
0 0
1 1
1 0

result:

ok correct

Test #10:

score: -12
Time Limit Exceeded

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:

392
92 63
72 28
35 75
68 78
54 13
57 74
18 51
73 16
94 94
61 39
6 81
95 46
58 76
87 91
96 61
67 10
15 1
1 47
58 47
30 72
71 52
29 79
7 3
71 75
84 52
81 88
55 54
89 24
84 45
71 87
58 73
35 9
88 68
68 44
4 48
96 72
93 12
59 83
97 58
85 50
2 33
46 72
69 80
42 48
92 67
82 82
75 81
76 94
88 14
81 44
41 8...

result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #13:

score: 16
Accepted
time: 76ms
memory: 3660kb

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:

8
1 1
1 0
0 1
0 0
1 0
0 0
1 1
1 0

result:

ok correct

Test #14:

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

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:

20
2 2
4 0
1 4
4 0
1 1
3 3
2 1
0 4
3 3
1 2
2 2
4 3
2 0
1 3
0 1
2 4
3 4
1 0
4 4
3 2

result:

ok correct

Test #15:

score: 0
Accepted
time: 979ms
memory: 3768kb

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:

384
12 57
7 61
68 87
65 22
86 45
92 56
93 23
83 32
54 45
71 35
45 44
58 74
38 12
49 10
25 20
50 85
56 40
52 29
91 76
58 93
82 21
60 91
84 51
91 12
24 2
18 79
54 74
59 14
21 58
75 24
1 36
14 34
29 39
64 2
73 5
38 48
66 0
72 16
88 71
18 38
36 65
47 19
48 53
80 74
54 71
45 13
89 71
36 19
37 18
56 46
90...

result:

ok correct

Test #16:

score: -16
Time Limit Exceeded

input:

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

output:

396
75 26
81 90
29 70
74 90
64 64
42 29
2 45
31 47
62 94
58 0
60 97
41 6
12 2
64 57
16 89
13 26
14 70
36 79
73 40
60 72
6 16
40 80
98 58
11 51
81 90
88 42
92 43
95 27
98 28
95 23
23 19
12 78
82 91
97 79
95 52
19 2
31 12
9 28
56 81
27 78
31 46
0 75
43 32
69 7
31 30
77 10
56 19
83 54
7 3
65 87
17 43
3...

result:


Subtask #4:

score: 0
Skipped

Dependency #2:

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%