Submission #554822

# Submission time Handle Problem Language Result Execution time Memory
554822 2022-04-29T13:20:09 Z andrei_boaca Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
55 ms 66728 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll INF=1e14;
ll n,l,x[205],t[205],dist[205][205],dp[205][205][205][2],ans;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>l;
    for(int i=1;i<=n;i++)
        cin>>x[i];
    for(int i=1;i<=n;i++)
        cin>>t[i];
    for(int i=0;i<=n+1;i++)
        for(int j=0;j<=n+1;j++)
        {
            dist[i][j]=abs(x[i]-x[j]);
            dist[i][j]=min(dist[i][j],l-dist[i][j]);
        }
    for(int i=0;i<=n;i++)
        for(int j=0;j+i<=n;j++)
        {
            for(int take=0;take<=n;take++)
            {
                dp[i][j][take][0]=dp[i][j][take][1]=INF;
                if(i==0&&j==0&&take==0)
                {
                    dp[i][j][take][0]=dp[i][j][take][1]=0;
                    continue;
                }
                if(i-1>=0)
                {
                    ll val=INF;
                    val=min(val,dp[i-1][j][take][0]+dist[i][i-1]);
                    val=min(val,dp[i-1][j][take][1]+dist[i][n-j+1]);
                    if(take>0)
                    {
                        if(dp[i-1][j][take-1][0]+dist[i][i-1]<=t[i])
                            val=min(val,dp[i-1][j][take-1][0]+dist[i][i-1]);
                        if(dp[i-1][j][take-1][1]+dist[i][n-j+1]<=t[i])
                            val=min(val,dp[i-1][j][take-1][1]+dist[i][n-j+1]);
                    }
                    dp[i][j][take][0]=val;
                }
                if(j-1>=0)
                {
                    ll val=INF;
                    val=min(val,dp[i][j-1][take][0]+dist[i][n-j+1]);
                    val=min(val,dp[i][j-1][take][1]+dist[n-(j-1)+1][n-j+1]);
                    if(take>0)
                    {
                        if(dp[i][j-1][take-1][0]+dist[i][n-j+1]<=t[n-j+1])
                            val=min(val,dp[i][j-1][take-1][0]+dist[i][n-j+1]);
                        if(dp[i][j-1][take-1][1]+dist[n-(j-1)+1][n-j+1]<=t[n-j+1])
                            val=min(val,dp[i][j-1][take-1][1]+dist[n-(j-1)+1][n-j+1]);
                    }
                    dp[i][j][take][1]=val;
                }
                if(min(dp[i][j][take][1],dp[i][j][take][0])<INF)
                    ans=max(ans,1LL*take);
            }
        }
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 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 1 ms 340 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 456 KB Output is correct
15 Correct 1 ms 452 KB Output is correct
16 Correct 1 ms 596 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 340 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 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 1 ms 340 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 456 KB Output is correct
15 Correct 1 ms 452 KB Output is correct
16 Correct 1 ms 596 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 596 KB Output is correct
21 Correct 1 ms 712 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 468 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 724 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 340 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 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 1 ms 340 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 456 KB Output is correct
15 Correct 1 ms 452 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 38 ms 53580 KB Output is correct
19 Correct 21 ms 32712 KB Output is correct
20 Correct 11 ms 17596 KB Output is correct
21 Correct 21 ms 30908 KB Output is correct
22 Correct 29 ms 39936 KB Output is correct
23 Correct 9 ms 15060 KB Output is correct
24 Correct 7 ms 11860 KB Output is correct
25 Correct 12 ms 14744 KB Output is correct
26 Correct 4 ms 5844 KB Output is correct
27 Correct 11 ms 15304 KB Output is correct
28 Correct 6 ms 11092 KB Output is correct
29 Correct 9 ms 15684 KB Output is correct
30 Correct 7 ms 12392 KB Output is correct
31 Correct 8 ms 14804 KB Output is correct
32 Correct 4 ms 7892 KB Output is correct
33 Correct 12 ms 14692 KB Output is correct
34 Correct 4 ms 5460 KB Output is correct
35 Correct 8 ms 14384 KB Output is correct
36 Correct 4 ms 7020 KB Output is correct
37 Correct 9 ms 15316 KB Output is correct
38 Correct 5 ms 8532 KB Output is correct
39 Correct 9 ms 15956 KB Output is correct
40 Correct 5 ms 9572 KB Output is correct
41 Correct 51 ms 65984 KB Output is correct
42 Correct 28 ms 44632 KB Output is correct
43 Correct 49 ms 66044 KB Output is correct
44 Correct 28 ms 44060 KB Output is correct
45 Correct 48 ms 66020 KB Output is correct
46 Correct 31 ms 44660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 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 1 ms 340 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 456 KB Output is correct
15 Correct 1 ms 452 KB Output is correct
16 Correct 1 ms 596 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 596 KB Output is correct
21 Correct 1 ms 712 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 468 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 724 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 38 ms 53580 KB Output is correct
37 Correct 21 ms 32712 KB Output is correct
38 Correct 11 ms 17596 KB Output is correct
39 Correct 21 ms 30908 KB Output is correct
40 Correct 29 ms 39936 KB Output is correct
41 Correct 9 ms 15060 KB Output is correct
42 Correct 7 ms 11860 KB Output is correct
43 Correct 12 ms 14744 KB Output is correct
44 Correct 4 ms 5844 KB Output is correct
45 Correct 11 ms 15304 KB Output is correct
46 Correct 6 ms 11092 KB Output is correct
47 Correct 9 ms 15684 KB Output is correct
48 Correct 7 ms 12392 KB Output is correct
49 Correct 8 ms 14804 KB Output is correct
50 Correct 4 ms 7892 KB Output is correct
51 Correct 12 ms 14692 KB Output is correct
52 Correct 4 ms 5460 KB Output is correct
53 Correct 8 ms 14384 KB Output is correct
54 Correct 4 ms 7020 KB Output is correct
55 Correct 9 ms 15316 KB Output is correct
56 Correct 5 ms 8532 KB Output is correct
57 Correct 9 ms 15956 KB Output is correct
58 Correct 5 ms 9572 KB Output is correct
59 Correct 51 ms 65984 KB Output is correct
60 Correct 28 ms 44632 KB Output is correct
61 Correct 49 ms 66044 KB Output is correct
62 Correct 28 ms 44060 KB Output is correct
63 Correct 48 ms 66020 KB Output is correct
64 Correct 31 ms 44660 KB Output is correct
65 Correct 50 ms 59652 KB Output is correct
66 Correct 39 ms 54796 KB Output is correct
67 Correct 45 ms 52516 KB Output is correct
68 Correct 32 ms 48412 KB Output is correct
69 Correct 43 ms 58972 KB Output is correct
70 Correct 41 ms 56620 KB Output is correct
71 Correct 41 ms 57148 KB Output is correct
72 Correct 44 ms 57804 KB Output is correct
73 Correct 39 ms 53580 KB Output is correct
74 Correct 35 ms 50092 KB Output is correct
75 Correct 40 ms 55372 KB Output is correct
76 Correct 46 ms 63428 KB Output is correct
77 Correct 45 ms 63436 KB Output is correct
78 Correct 36 ms 48996 KB Output is correct
79 Correct 34 ms 50672 KB Output is correct
80 Correct 47 ms 62172 KB Output is correct
81 Correct 37 ms 51324 KB Output is correct
82 Correct 37 ms 54220 KB Output is correct
83 Correct 47 ms 66012 KB Output is correct
84 Correct 40 ms 56540 KB Output is correct
85 Correct 43 ms 61556 KB Output is correct
86 Correct 42 ms 60232 KB Output is correct
87 Correct 38 ms 55320 KB Output is correct
88 Correct 55 ms 66728 KB Output is correct
89 Correct 49 ms 66624 KB Output is correct
90 Correct 38 ms 55996 KB Output is correct
91 Correct 48 ms 66636 KB Output is correct
92 Correct 51 ms 66664 KB Output is correct
93 Correct 47 ms 65356 KB Output is correct