Submission #796940

# Submission time Handle Problem Language Result Execution time Memory
796940 2023-07-28T23:49:05 Z cfhater Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
308 ms 65128 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
// #define int ll

const ll INF = 1e18;
const int MAXN = 201, MOD = 1e9 + 7;

int n, l;
ll dp[MAXN][MAXN][MAXN][2];

inline ll dist(int a, int b) {
    return min(((a - b) % l + l) % l, ((b - a) % l + l) % l);
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> n >> l;
    vector<pair<int, int>> left(n);
    for (auto& i : left)
        cin >> i.first;
    for (auto& i : left)
        cin >> i.second;
    auto right = left;
    left.push_back({0, 0});
    right.push_back({l, 0});
    sort(all(left));
    sort(rall(right));

    int res = 0;
    for (int lb = 0; lb <= n; lb++)
        for (int rb = 0; lb + rb <= n; rb++)
            for (int cnt = 0; cnt <= n; cnt++)
                dp[lb][rb][cnt][0] = dp[lb][rb][cnt][1] = INF;
    for (int lb = 1; lb <= n; lb++) {
        if (dist(0, left[lb].first) <= left[lb].second) {
            dp[lb][0][1][0] = dist(0, left[lb].first);
            dp[lb][0][1][1] = dp[lb][0][1][0] * 2;
            res = 1;
        }
    }
    for (int rb = 1; rb <= n; rb++) {
        if (dist(0, right[rb].first) <= right[rb].second) {
            dp[0][rb][1][1] = dist(0, right[rb].first);
            dp[0][rb][1][0] = dp[0][rb][1][1] * 2;
            res = 1;
        }
    }

    for (int cnt = 1; cnt <= n; cnt++) {
        for (int lb = 0; lb <= n; lb++) {
            for (int rb = 0; lb + rb <= n; rb++) {
                if (lb > 0)
                    dp[lb][rb][cnt][0] = min(dp[lb][rb][cnt][0], dp[lb - 1][rb][cnt][1] + dist(right[rb].first, left[lb].first));
                if (lb > 0)
                    dp[lb][rb][cnt][0] = min(dp[lb][rb][cnt][0], dp[lb - 1][rb][cnt][0] + dist(left[lb - 1].first, left[lb].first));
                if (lb > 0 and dp[lb - 1][rb][cnt - 1][0] + dist(left[lb - 1].first, left[lb].first) <= left[lb].second)
                    dp[lb][rb][cnt][0] = min(dp[lb][rb][cnt][0], dp[lb - 1][rb][cnt - 1][0] + dist(left[lb - 1].first, left[lb].first));
                if (lb > 0 and dp[lb - 1][rb][cnt - 1][1] + dist(right[rb].first, left[lb].first) <= left[lb].second)
                    dp[lb][rb][cnt][0] = min(dp[lb][rb][cnt][0], dp[lb - 1][rb][cnt - 1][1] + dist(right[rb].first, left[lb].first));

                if (rb > 0)
                    dp[lb][rb][cnt][1] = min(dp[lb][rb][cnt][1], dp[lb][rb - 1][cnt][0] + dist(left[lb].first, right[rb].first));
                if (rb > 0)
                    dp[lb][rb][cnt][1] = min(dp[lb][rb][cnt][1], dp[lb][rb - 1][cnt][1] + dist(right[rb - 1].first, right[rb].first));
                if (rb > 0 and dp[lb][rb - 1][cnt - 1][1] + dist(right[rb - 1].first, right[rb].first) <= right[rb].second)
                    dp[lb][rb][cnt][1] = min(dp[lb][rb][cnt][1], dp[lb][rb - 1][cnt - 1][1] + dist(right[rb - 1].first, right[rb].first));
                if (rb > 0 and dp[lb][rb - 1][cnt - 1][0] + dist(left[lb].first, right[rb].first) <= right[rb].second)
                    dp[lb][rb][cnt][1] = min(dp[lb][rb][cnt][1], dp[lb][rb - 1][cnt - 1][0] + dist(left[lb].first, right[rb].first));

                if (dp[lb][rb][cnt][0] != INF or dp[lb][rb][cnt][1] != INF)
                    res = max(res, cnt);
            }
        }
    }

    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 584 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 584 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 584 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 456 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 708 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 1 ms 724 KB Output is correct
35 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 584 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 221 ms 52360 KB Output is correct
19 Correct 107 ms 31956 KB Output is correct
20 Correct 43 ms 17164 KB Output is correct
21 Correct 98 ms 30148 KB Output is correct
22 Correct 146 ms 39116 KB Output is correct
23 Correct 34 ms 14616 KB Output is correct
24 Correct 24 ms 11476 KB Output is correct
25 Correct 33 ms 14284 KB Output is correct
26 Correct 9 ms 5588 KB Output is correct
27 Correct 35 ms 14932 KB Output is correct
28 Correct 22 ms 10736 KB Output is correct
29 Correct 37 ms 15276 KB Output is correct
30 Correct 26 ms 11988 KB Output is correct
31 Correct 33 ms 14372 KB Output is correct
32 Correct 13 ms 7624 KB Output is correct
33 Correct 33 ms 14388 KB Output is correct
34 Correct 8 ms 5332 KB Output is correct
35 Correct 32 ms 14028 KB Output is correct
36 Correct 12 ms 6856 KB Output is correct
37 Correct 35 ms 14912 KB Output is correct
38 Correct 15 ms 8264 KB Output is correct
39 Correct 37 ms 15572 KB Output is correct
40 Correct 17 ms 9172 KB Output is correct
41 Correct 301 ms 64484 KB Output is correct
42 Correct 170 ms 43596 KB Output is correct
43 Correct 302 ms 64480 KB Output is correct
44 Correct 166 ms 43080 KB Output is correct
45 Correct 303 ms 64476 KB Output is correct
46 Correct 169 ms 43576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 584 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 584 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 456 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 708 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 1 ms 724 KB Output is correct
35 Correct 1 ms 724 KB Output is correct
36 Correct 221 ms 52360 KB Output is correct
37 Correct 107 ms 31956 KB Output is correct
38 Correct 43 ms 17164 KB Output is correct
39 Correct 98 ms 30148 KB Output is correct
40 Correct 146 ms 39116 KB Output is correct
41 Correct 34 ms 14616 KB Output is correct
42 Correct 24 ms 11476 KB Output is correct
43 Correct 33 ms 14284 KB Output is correct
44 Correct 9 ms 5588 KB Output is correct
45 Correct 35 ms 14932 KB Output is correct
46 Correct 22 ms 10736 KB Output is correct
47 Correct 37 ms 15276 KB Output is correct
48 Correct 26 ms 11988 KB Output is correct
49 Correct 33 ms 14372 KB Output is correct
50 Correct 13 ms 7624 KB Output is correct
51 Correct 33 ms 14388 KB Output is correct
52 Correct 8 ms 5332 KB Output is correct
53 Correct 32 ms 14028 KB Output is correct
54 Correct 12 ms 6856 KB Output is correct
55 Correct 35 ms 14912 KB Output is correct
56 Correct 15 ms 8264 KB Output is correct
57 Correct 37 ms 15572 KB Output is correct
58 Correct 17 ms 9172 KB Output is correct
59 Correct 301 ms 64484 KB Output is correct
60 Correct 170 ms 43596 KB Output is correct
61 Correct 302 ms 64480 KB Output is correct
62 Correct 166 ms 43080 KB Output is correct
63 Correct 303 ms 64476 KB Output is correct
64 Correct 169 ms 43576 KB Output is correct
65 Correct 259 ms 58256 KB Output is correct
66 Correct 233 ms 53520 KB Output is correct
67 Correct 216 ms 51144 KB Output is correct
68 Correct 191 ms 47316 KB Output is correct
69 Correct 258 ms 57672 KB Output is correct
70 Correct 242 ms 55244 KB Output is correct
71 Correct 244 ms 55840 KB Output is correct
72 Correct 248 ms 56464 KB Output is correct
73 Correct 221 ms 52344 KB Output is correct
74 Correct 202 ms 48980 KB Output is correct
75 Correct 239 ms 54116 KB Output is correct
76 Correct 286 ms 61968 KB Output is correct
77 Correct 286 ms 61968 KB Output is correct
78 Correct 195 ms 47828 KB Output is correct
79 Correct 205 ms 49524 KB Output is correct
80 Correct 278 ms 60716 KB Output is correct
81 Correct 207 ms 49996 KB Output is correct
82 Correct 226 ms 52812 KB Output is correct
83 Correct 303 ms 64480 KB Output is correct
84 Correct 239 ms 55240 KB Output is correct
85 Correct 275 ms 60088 KB Output is correct
86 Correct 264 ms 58892 KB Output is correct
87 Correct 232 ms 54016 KB Output is correct
88 Correct 307 ms 65100 KB Output is correct
89 Correct 308 ms 65052 KB Output is correct
90 Correct 236 ms 54692 KB Output is correct
91 Correct 308 ms 65120 KB Output is correct
92 Correct 306 ms 65128 KB Output is correct
93 Correct 300 ms 63836 KB Output is correct