Submission #967386

# Submission time Handle Problem Language Result Execution time Memory
967386 2024-04-22T03:58:47 Z 12345678 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
96 ms 130156 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int nx=205;

ll n, d, a[nx], t[nx], dp[nx][nx][nx][2], res;

ll dist(ll a, ll b)
{
    if (a>b) swap(a, b);
    return min(b-a, a+d-b);
}

ll nxt(ll x)
{
    if (x+1>n) return x+1-n;
    return x+1;
}

ll prv(ll x)
{
    if (x-1>0) return x-1;
    return x-1+n;
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>d;
    for (int i=1; i<=n; i++) cin>>a[i];
    for (int i=1; i<=n; i++) cin>>t[i];
    for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) for (int k=1; k<=n; k++) dp[i][j][k][0]=dp[i][j][k][1]=1e18;
    for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) dp[i][j][0][0]=dist(0, a[i]), dp[i][j][0][1]=dist(0, a[j]);
    for (int i=1; i<=n; i++) if (dist(0, a[i])<=t[i]) dp[i][i][1][0]=dp[i][i][1][1]=dist(0, a[i]);
    for (int i=1; i<n; i++)
    {
        for (int j=1; j<=n; j++)
        {
            ll l=j, r=j+i;
            if (r>n) r-=n;
            for (int k=1; k<=i+1; k++)
            {
                dp[l][r][k][0]=min({dp[l][r][k][0], dp[nxt(l)][r][k][0]+dist(a[l], a[nxt(l)]), dp[nxt(l)][r][k][1]+dist(a[l], a[r])});
                if (dp[nxt(l)][r][k-1][0]+dist(a[nxt(l)], a[l])<=t[l]) dp[l][r][k][0]=min(dp[l][r][k][0], dp[nxt(l)][r][k-1][0]+dist(a[nxt(l)], a[l]));
                if (dp[nxt(l)][r][k-1][1]+dist(a[l], a[r])<=t[l]) dp[l][r][k][0]=min(dp[l][r][k][0], dp[nxt(l)][r][k-1][1]+dist(a[l], a[r]));
                dp[l][r][k][1]=min({dp[l][r][k][1], dp[l][prv(r)][k][0]+dist(a[l], a[r]), dp[l][prv(r)][k][1]+dist(a[prv(r)], a[r])});
                if (dp[l][prv(r)][k-1][0]+dist(a[l], a[r])<=t[r]) dp[l][r][k][1]=min(dp[l][r][k][1], dp[l][prv(r)][k-1][0]+dist(a[l], a[r]));
                if (dp[l][prv(r)][k-1][1]+dist(a[prv(r)], a[r])<=t[r]) dp[l][r][k][1]=min(dp[l][r][k][1], dp[l][prv(r)][k-1][1]+dist(a[prv(r)], a[r]));
                //cout<<"debug "<<l<<' '<<r<<' '<<k<<' '<<dp[l][r][k][0]<<' '<<dp[l][r][k][1]<<'\n';
            }
        }
    }
    for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) for (int k=1; k<=n; k++) for (int t=0; t<2; t++) if (dp[i][j][k][t]<1e18) res=max(res, (ll)k);
    cout<<res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 6612 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8536 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 6612 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8536 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 1 ms 10588 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6604 KB Output is correct
29 Correct 2 ms 10584 KB Output is correct
30 Correct 1 ms 10588 KB Output is correct
31 Correct 2 ms 10588 KB Output is correct
32 Correct 1 ms 10588 KB Output is correct
33 Correct 2 ms 10588 KB Output is correct
34 Correct 2 ms 10588 KB Output is correct
35 Correct 2 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 6612 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8536 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 66 ms 106064 KB Output is correct
19 Correct 42 ms 67784 KB Output is correct
20 Correct 20 ms 38748 KB Output is correct
21 Correct 39 ms 63700 KB Output is correct
22 Correct 50 ms 80212 KB Output is correct
23 Correct 17 ms 35416 KB Output is correct
24 Correct 12 ms 28508 KB Output is correct
25 Correct 18 ms 32348 KB Output is correct
26 Correct 5 ms 16476 KB Output is correct
27 Correct 19 ms 33500 KB Output is correct
28 Correct 11 ms 24412 KB Output is correct
29 Correct 17 ms 34140 KB Output is correct
30 Correct 13 ms 28252 KB Output is correct
31 Correct 16 ms 31324 KB Output is correct
32 Correct 7 ms 17244 KB Output is correct
33 Correct 18 ms 30044 KB Output is correct
34 Correct 5 ms 12892 KB Output is correct
35 Correct 15 ms 29532 KB Output is correct
36 Correct 8 ms 15704 KB Output is correct
37 Correct 16 ms 31324 KB Output is correct
38 Correct 8 ms 18524 KB Output is correct
39 Correct 18 ms 32344 KB Output is correct
40 Correct 9 ms 20316 KB Output is correct
41 Correct 88 ms 128884 KB Output is correct
42 Correct 54 ms 87388 KB Output is correct
43 Correct 87 ms 129116 KB Output is correct
44 Correct 54 ms 86240 KB Output is correct
45 Correct 85 ms 128884 KB Output is correct
46 Correct 58 ms 87380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 6612 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8536 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 1 ms 10588 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6604 KB Output is correct
29 Correct 2 ms 10584 KB Output is correct
30 Correct 1 ms 10588 KB Output is correct
31 Correct 2 ms 10588 KB Output is correct
32 Correct 1 ms 10588 KB Output is correct
33 Correct 2 ms 10588 KB Output is correct
34 Correct 2 ms 10588 KB Output is correct
35 Correct 2 ms 10588 KB Output is correct
36 Correct 66 ms 106064 KB Output is correct
37 Correct 42 ms 67784 KB Output is correct
38 Correct 20 ms 38748 KB Output is correct
39 Correct 39 ms 63700 KB Output is correct
40 Correct 50 ms 80212 KB Output is correct
41 Correct 17 ms 35416 KB Output is correct
42 Correct 12 ms 28508 KB Output is correct
43 Correct 18 ms 32348 KB Output is correct
44 Correct 5 ms 16476 KB Output is correct
45 Correct 19 ms 33500 KB Output is correct
46 Correct 11 ms 24412 KB Output is correct
47 Correct 17 ms 34140 KB Output is correct
48 Correct 13 ms 28252 KB Output is correct
49 Correct 16 ms 31324 KB Output is correct
50 Correct 7 ms 17244 KB Output is correct
51 Correct 18 ms 30044 KB Output is correct
52 Correct 5 ms 12892 KB Output is correct
53 Correct 15 ms 29532 KB Output is correct
54 Correct 8 ms 15704 KB Output is correct
55 Correct 16 ms 31324 KB Output is correct
56 Correct 8 ms 18524 KB Output is correct
57 Correct 18 ms 32344 KB Output is correct
58 Correct 9 ms 20316 KB Output is correct
59 Correct 88 ms 128884 KB Output is correct
60 Correct 54 ms 87388 KB Output is correct
61 Correct 87 ms 129116 KB Output is correct
62 Correct 54 ms 86240 KB Output is correct
63 Correct 85 ms 128884 KB Output is correct
64 Correct 58 ms 87380 KB Output is correct
65 Correct 75 ms 116308 KB Output is correct
66 Correct 69 ms 107100 KB Output is correct
67 Correct 76 ms 102428 KB Output is correct
68 Correct 62 ms 94800 KB Output is correct
69 Correct 73 ms 115328 KB Output is correct
70 Correct 75 ms 110396 KB Output is correct
71 Correct 70 ms 111584 KB Output is correct
72 Correct 75 ms 112964 KB Output is correct
73 Correct 67 ms 104832 KB Output is correct
74 Correct 66 ms 98068 KB Output is correct
75 Correct 80 ms 108292 KB Output is correct
76 Correct 85 ms 123868 KB Output is correct
77 Correct 79 ms 123872 KB Output is correct
78 Correct 63 ms 95928 KB Output is correct
79 Correct 73 ms 99216 KB Output is correct
80 Correct 82 ms 121392 KB Output is correct
81 Correct 66 ms 100332 KB Output is correct
82 Correct 69 ms 105808 KB Output is correct
83 Correct 83 ms 128892 KB Output is correct
84 Correct 70 ms 110540 KB Output is correct
85 Correct 76 ms 120064 KB Output is correct
86 Correct 82 ms 117704 KB Output is correct
87 Correct 70 ms 108268 KB Output is correct
88 Correct 88 ms 130128 KB Output is correct
89 Correct 88 ms 130156 KB Output is correct
90 Correct 68 ms 109376 KB Output is correct
91 Correct 96 ms 130028 KB Output is correct
92 Correct 87 ms 130132 KB Output is correct
93 Correct 81 ms 127572 KB Output is correct