QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#577409#8528. Chordsucup-team3519WA 2788ms3916kbC++202.0kb2024-09-20 11:12:132024-09-20 11:12:13

Judging History

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

  • [2024-09-20 11:12:13]
  • 评测
  • 测评结果:WA
  • 用时:2788ms
  • 内存:3916kb
  • [2024-09-20 11:12:13]
  • 提交

answer

#include <bits/stdc++.h>

std::mt19937 rng(std::random_device{}());

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;

    std::vector<int> buk;
    std::vector<std::pair<int, int>> edge(n * 4 + 1), redge(n * 4 + 1);
    for (int i = 1; i <= n; ++i) {
        int u, v;
        std::cin >> u >> v;

        edge[u] = {v, i};
        redge[v] = {u, i};

        edge[v] = {u + n * 2, i + n};
        redge[u + n * 2] = {v, i + n};

        buk.push_back(v);
        buk.push_back(u + n * 2);
    }

    std::vector<int> vals(n * 2 + 1, 1);

    std::vector<int> dp(n * 4 + 2);
    auto iterate = [&]() -> int {
        int res = 0;

        int mid = buk[rng() % buk.size()];
        int l = std::max<int>(mid - n * 1.6, 1),
            r = std::min<int>(mid + n * 1.6, n * 4);

        dp[mid] = 0;
        for (int i = mid - 1; i >= l; --i) {
            dp[i] = dp[i + 1];

            auto [to, id] = edge[i];
            if (to && to <= mid) {
                dp[i] = std::max(dp[i], dp[to] + vals[id]);
            }
        }

        dp[mid + 1] = 0;
        for (int i = mid + 2; i <= r; ++i) {
            dp[i] = dp[i - 1];

            auto [to, id] = redge[i];
            if (to && to > mid) {
                dp[i] = std::max(dp[i], dp[to] + vals[id]);
            }
        }

        for (int i = l; i <= mid; ++i) {
            auto [to, id] = edge[i];

            if (to && to > mid) {
                vals[id] = std::max(vals[id], dp[i] + dp[to] + 1);
            }
            if (i + n * 2 - 1 > mid && i + n * 2 - 1 <= n * 4) {
                res = std::max(res, dp[i] + dp[i + n * 2 - 1]);
            }
        }
        return res;
    };

    int ans = 1;

    auto s = clock();
    while (double(clock() - s) / CLOCKS_PER_SEC < 2.8) {
        for (int _ = 0; _ < 20; ++_) {
            ans = std::max(ans, iterate());
        }
    }

    std::cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2555ms
memory: 3596kb

input:

5
1 2
4 10
7 9
3 5
6 8

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 2356ms
memory: 3664kb

input:

1
1 2

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 2500ms
memory: 3656kb

input:

2
1 3
2 4

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 2520ms
memory: 3656kb

input:

2
1 4
2 3

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 2472ms
memory: 3596kb

input:

3
3 5
1 4
2 6

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 2548ms
memory: 3680kb

input:

4
2 7
1 6
3 8
4 5

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 2532ms
memory: 3916kb

input:

6
8 9
6 7
4 10
1 5
11 12
2 3

output:

5

result:

ok 1 number(s): "5"

Test #8:

score: 0
Accepted
time: 2656ms
memory: 3688kb

input:

9
2 8
10 17
9 15
1 12
6 14
3 13
4 11
5 7
16 18

output:

4

result:

ok 1 number(s): "4"

Test #9:

score: 0
Accepted
time: 2716ms
memory: 3668kb

input:

13
8 16
2 13
14 23
10 11
7 17
6 24
12 18
9 20
4 15
19 21
3 26
1 25
5 22

output:

6

result:

ok 1 number(s): "6"

Test #10:

score: 0
Accepted
time: 2743ms
memory: 3684kb

input:

19
34 35
4 20
9 31
12 17
18 38
23 29
19 30
25 26
10 36
1 7
13 37
2 11
8 32
6 28
16 24
5 27
14 21
15 22
3 33

output:

8

result:

ok 1 number(s): "8"

Test #11:

score: 0
Accepted
time: 2728ms
memory: 3592kb

input:

28
9 45
7 19
15 40
42 44
26 31
20 22
16 55
6 34
41 56
28 51
2 33
36 53
3 13
37 52
4 46
12 48
21 27
24 30
23 38
1 32
8 14
43 54
11 17
47 49
29 35
5 25
18 39
10 50

output:

10

result:

ok 1 number(s): "10"

Test #12:

score: 0
Accepted
time: 2780ms
memory: 3896kb

input:

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

output:

11

result:

ok 1 number(s): "11"

Test #13:

score: 0
Accepted
time: 2780ms
memory: 3668kb

input:

63
40 105
6 104
45 83
16 22
31 34
51 57
64 92
75 112
70 82
65 121
32 93
18 60
30 68
72 77
86 101
10 47
85 94
36 71
11 35
27 126
56 74
15 52
19 91
88 110
76 97
25 33
58 109
42 54
12 26
73 107
99 118
29 106
44 90
3 9
23 122
14 79
87 116
4 81
17 111
41 53
50 123
38 124
13 114
67 96
5 100
55 115
43 62
4...

output:

17

result:

ok 1 number(s): "17"

Test #14:

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

input:

94
109 118
69 152
93 185
111 162
17 188
15 175
35 123
13 95
72 186
83 160
52 117
24 159
128 163
56 179
141 168
25 58
44 82
47 53
78 172
100 105
70 106
143 164
4 88
99 182
98 146
57 77
38 112
91 149
45 174
125 138
26 34
37 121
62 134
97 187
2 66
22 40
153 181
86 108
19 155
33 130
103 177
11 21
18 126...

output:

21

result:

ok 1 number(s): "21"

Test #15:

score: -100
Wrong Answer
time: 2788ms
memory: 3840kb

input:

141
31 127
1 73
84 94
158 254
129 208
35 114
112 201
182 222
18 259
27 267
67 271
14 160
22 269
89 161
57 58
49 86
8 184
202 256
24 43
194 198
225 273
204 265
79 270
66 249
54 250
130 268
26 162
165 261
197 257
119 279
216 232
21 274
151 179
106 140
28 48
122 206
65 186
3 177
90 92
15 105
163 262
14...

output:

31

result:

wrong answer 1st numbers differ - expected: '32', found: '31'