Submission #540938

# Submission time Handle Problem Language Result Execution time Memory
540938 2022-03-22T03:07:15 Z LittleCube Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
373 ms 517584 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

ll N, L, dp[405][405][205][2], dis[405][405], ans;
pll a[405];

signed main()
{
    cin >> N >> L;
    for (int i = 1; i <= N; i++)
        cin >> a[i].F;
    for (int i = 1; i <= N; i++)
        cin >> a[i].S;
    for (int i = 1; i <= N; i++)
    {
        a[i + N] = a[i];
        a[i].F -= L;
    }
    N *= 2;
    for (int i = 1; i <= N; i++)
        for (int j = i + 1; j <= N; j++)
            dis[i][j] = dis[i][j - 1] + a[j].F - a[j - 1].F;
    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= N; j++)
            for (int k = 0; k <= N / 2; k++)
                dp[i][j][k][0] = dp[i][j][k][1] = 2e17;

    for (int i = 1; i <= N; i++)
        dp[i][i][abs(a[i].S) >= abs(a[i].F)][0] = dp[i][i][abs(a[i].S) >= abs(a[i].F)][1] = abs(a[i].F);

    for (int len = 0; len < N / 2; len++)
        for (int i = 1; i <= N; i++)
        {
            int j = i + len;
            if (j <= N)
                for (int k = 0; k <= len + 1; k++)
                    if (dp[i][j][k][0] <= 1e17 || dp[i][j][k][1] <= 1e17)
                    {
                        // printf("%d %d %d %d = %lld\n", i, j, k, 0, dp[i][j][k][0]);
                        // printf("%d %d %d %d = %lld\n", i, j, k, 1, dp[i][j][k][1]);
                        ans = max(ans, (ll)k);
                        int dk = (dp[i][j][k][0] + dis[i - 1][i] <= a[i - 1].S);
                        dp[i - 1][j][k + dk][0] = min(dp[i - 1][j][k + dk][0], dp[i][j][k][0] + dis[i - 1][i]);

                        dk = (dp[i][j][k][0] + dis[i][j + 1] <= a[j + 1].S);
                        dp[i][j + 1][k + dk][1] = min(dp[i][j + 1][k + dk][1], dp[i][j][k][0] + dis[i][j + 1]);

                        dk = (dp[i][j][k][1] + dis[i - 1][j] <= a[i - 1].S);
                        dp[i - 1][j][k + dk][0] = min(dp[i - 1][j][k + dk][0], dp[i][j][k][1] + dis[i - 1][j]);

                        dk = (dp[i][j][k][1] + dis[j][j + 1] <= a[j + 1].S);
                        dp[i][j + 1][k + dk][1] = min(dp[i][j + 1][k + dk][1], dp[i][j][k][1] + dis[j][j + 1]);
                    }
        }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 1464 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 2 ms 2388 KB Output is correct
7 Correct 1 ms 1204 KB Output is correct
8 Correct 1 ms 1748 KB Output is correct
9 Correct 1 ms 2388 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 2388 KB Output is correct
13 Correct 1 ms 2340 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 2388 KB Output is correct
17 Correct 1 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 1464 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 2 ms 2388 KB Output is correct
7 Correct 1 ms 1204 KB Output is correct
8 Correct 1 ms 1748 KB Output is correct
9 Correct 1 ms 2388 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 2388 KB Output is correct
13 Correct 1 ms 2340 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 2388 KB Output is correct
17 Correct 1 ms 2388 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 1 ms 1748 KB Output is correct
20 Correct 1 ms 2388 KB Output is correct
21 Correct 2 ms 2988 KB Output is correct
22 Correct 1 ms 1492 KB Output is correct
23 Correct 2 ms 3412 KB Output is correct
24 Correct 1 ms 2612 KB Output is correct
25 Correct 2 ms 3000 KB Output is correct
26 Correct 1 ms 3028 KB Output is correct
27 Correct 1 ms 1204 KB Output is correct
28 Correct 1 ms 1492 KB Output is correct
29 Correct 2 ms 3412 KB Output is correct
30 Correct 2 ms 3412 KB Output is correct
31 Correct 2 ms 3028 KB Output is correct
32 Correct 1 ms 2644 KB Output is correct
33 Correct 2 ms 3384 KB Output is correct
34 Correct 2 ms 3412 KB Output is correct
35 Correct 2 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 1464 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 2 ms 2388 KB Output is correct
7 Correct 1 ms 1204 KB Output is correct
8 Correct 1 ms 1748 KB Output is correct
9 Correct 1 ms 2388 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 2388 KB Output is correct
13 Correct 1 ms 2340 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 2388 KB Output is correct
17 Correct 1 ms 2388 KB Output is correct
18 Correct 302 ms 414776 KB Output is correct
19 Correct 149 ms 250872 KB Output is correct
20 Correct 70 ms 133036 KB Output is correct
21 Correct 133 ms 236684 KB Output is correct
22 Correct 182 ms 307620 KB Output is correct
23 Correct 62 ms 113088 KB Output is correct
24 Correct 42 ms 88036 KB Output is correct
25 Correct 60 ms 110636 KB Output is correct
26 Correct 20 ms 41556 KB Output is correct
27 Correct 64 ms 115468 KB Output is correct
28 Correct 42 ms 81944 KB Output is correct
29 Correct 61 ms 117844 KB Output is correct
30 Correct 46 ms 92424 KB Output is correct
31 Correct 62 ms 110648 KB Output is correct
32 Correct 28 ms 57444 KB Output is correct
33 Correct 56 ms 110668 KB Output is correct
34 Correct 18 ms 38664 KB Output is correct
35 Correct 51 ms 108244 KB Output is correct
36 Correct 29 ms 50736 KB Output is correct
37 Correct 60 ms 115436 KB Output is correct
38 Correct 31 ms 62684 KB Output is correct
39 Correct 58 ms 120368 KB Output is correct
40 Correct 39 ms 70020 KB Output is correct
41 Correct 341 ms 512444 KB Output is correct
42 Correct 158 ms 344288 KB Output is correct
43 Correct 324 ms 512340 KB Output is correct
44 Correct 160 ms 340124 KB Output is correct
45 Correct 318 ms 512372 KB Output is correct
46 Correct 164 ms 344224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 1464 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 2 ms 2388 KB Output is correct
7 Correct 1 ms 1204 KB Output is correct
8 Correct 1 ms 1748 KB Output is correct
9 Correct 1 ms 2388 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 2388 KB Output is correct
13 Correct 1 ms 2340 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 2388 KB Output is correct
17 Correct 1 ms 2388 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 1 ms 1748 KB Output is correct
20 Correct 1 ms 2388 KB Output is correct
21 Correct 2 ms 2988 KB Output is correct
22 Correct 1 ms 1492 KB Output is correct
23 Correct 2 ms 3412 KB Output is correct
24 Correct 1 ms 2612 KB Output is correct
25 Correct 2 ms 3000 KB Output is correct
26 Correct 1 ms 3028 KB Output is correct
27 Correct 1 ms 1204 KB Output is correct
28 Correct 1 ms 1492 KB Output is correct
29 Correct 2 ms 3412 KB Output is correct
30 Correct 2 ms 3412 KB Output is correct
31 Correct 2 ms 3028 KB Output is correct
32 Correct 1 ms 2644 KB Output is correct
33 Correct 2 ms 3384 KB Output is correct
34 Correct 2 ms 3412 KB Output is correct
35 Correct 2 ms 3412 KB Output is correct
36 Correct 302 ms 414776 KB Output is correct
37 Correct 149 ms 250872 KB Output is correct
38 Correct 70 ms 133036 KB Output is correct
39 Correct 133 ms 236684 KB Output is correct
40 Correct 182 ms 307620 KB Output is correct
41 Correct 62 ms 113088 KB Output is correct
42 Correct 42 ms 88036 KB Output is correct
43 Correct 60 ms 110636 KB Output is correct
44 Correct 20 ms 41556 KB Output is correct
45 Correct 64 ms 115468 KB Output is correct
46 Correct 42 ms 81944 KB Output is correct
47 Correct 61 ms 117844 KB Output is correct
48 Correct 46 ms 92424 KB Output is correct
49 Correct 62 ms 110648 KB Output is correct
50 Correct 28 ms 57444 KB Output is correct
51 Correct 56 ms 110668 KB Output is correct
52 Correct 18 ms 38664 KB Output is correct
53 Correct 51 ms 108244 KB Output is correct
54 Correct 29 ms 50736 KB Output is correct
55 Correct 60 ms 115436 KB Output is correct
56 Correct 31 ms 62684 KB Output is correct
57 Correct 58 ms 120368 KB Output is correct
58 Correct 39 ms 70020 KB Output is correct
59 Correct 341 ms 512444 KB Output is correct
60 Correct 158 ms 344288 KB Output is correct
61 Correct 324 ms 512340 KB Output is correct
62 Correct 160 ms 340124 KB Output is correct
63 Correct 318 ms 512372 KB Output is correct
64 Correct 164 ms 344224 KB Output is correct
65 Correct 254 ms 462576 KB Output is correct
66 Correct 235 ms 424080 KB Output is correct
67 Correct 218 ms 405688 KB Output is correct
68 Correct 207 ms 374388 KB Output is correct
69 Correct 254 ms 457408 KB Output is correct
70 Correct 278 ms 438312 KB Output is correct
71 Correct 234 ms 442852 KB Output is correct
72 Correct 307 ms 447864 KB Output is correct
73 Correct 197 ms 414928 KB Output is correct
74 Correct 227 ms 387684 KB Output is correct
75 Correct 215 ms 428664 KB Output is correct
76 Correct 296 ms 491948 KB Output is correct
77 Correct 261 ms 491888 KB Output is correct
78 Correct 210 ms 378752 KB Output is correct
79 Correct 217 ms 392124 KB Output is correct
80 Correct 276 ms 481860 KB Output is correct
81 Correct 207 ms 396504 KB Output is correct
82 Correct 219 ms 419468 KB Output is correct
83 Correct 275 ms 512184 KB Output is correct
84 Correct 229 ms 438184 KB Output is correct
85 Correct 268 ms 477092 KB Output is correct
86 Correct 250 ms 467020 KB Output is correct
87 Correct 256 ms 428964 KB Output is correct
88 Correct 339 ms 517584 KB Output is correct
89 Correct 327 ms 517384 KB Output is correct
90 Correct 199 ms 433368 KB Output is correct
91 Correct 373 ms 517508 KB Output is correct
92 Correct 331 ms 517556 KB Output is correct
93 Correct 217 ms 507072 KB Output is correct