Submission #391277

# Submission time Handle Problem Language Result Execution time Memory
391277 2021-04-18T11:37:56 Z wildturtle Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
204 ms 258416 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,c,d,i,e,f,g,n,m,k,l,A[202],dp[202][202][4][202],ans,T[202],j;
int main() {
    cin>>n>>l;
    for(ll i=1;i<=n;i++) {
        cin>>A[i];
    }
    for(ll i=1;i<=n;i++) {
        cin>>T[i];
    }
    n++;
    for(ll i=0;i<=n;i++) {
        for(ll j=0;j<=n;j++) {
            for(ll r=0;r<=1;r++) {
                for(ll cnt=0;cnt<=n;cnt++) {
                    dp[i][j][r][cnt]=1e18;
                }
            }
        }
    }
    A[n]=l;
    T[0]=-1;
    dp[0][n][0][0]=0;
    dp[0][n][1][0]=0;
    ans=0;
    for(ll sz=n-1;sz>=1;sz--) {
        for(ll i=0;i+sz<=n;i++) {
            j=i+sz;
            for(ll cnt=0;cnt<=n;cnt++) {
                if(i!=0) dp[i][j][0][cnt]=min(dp[i][j][0][cnt],dp[i-1][j][0][cnt]+A[i]-A[i-1]);
                if(j!=n) dp[i][j][1][cnt]=min(dp[i][j][1][cnt],dp[i][j+1][1][cnt]+A[j+1]-A[j]);
                if(cnt!=0) {
                    if(i!=0 && T[i]>=dp[i-1][j][0][cnt-1]+A[i]-A[i-1])
                    dp[i][j][0][cnt]=min(dp[i][j][0][cnt],dp[i-1][j][0][cnt-1]+A[i]-A[i-1]);
                    if(j!=n && T[j]>=dp[i][j+1][1][cnt-1]+A[j+1]-A[j]) 
                    dp[i][j][1][cnt]=min(dp[i][j][1][cnt],dp[i][j+1][1][cnt-1]+A[j+1]-A[j]);
                }
                dp[i][j][0][cnt]=min(dp[i][j][0][cnt],dp[i][j][1][cnt]+l-A[j]+A[i]);
                dp[i][j][1][cnt]=min(dp[i][j][1][cnt],dp[i][j][0][cnt]+l-A[j]+A[i]);
                if(dp[i][j][0][cnt]!=1e18 || dp[i][j][1][cnt]!=1e18) ans=max(ans,cnt);
            }
        }
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 2 ms 1356 KB Output is correct
7 Correct 1 ms 844 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1356 KB Output is correct
10 Correct 1 ms 292 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 1356 KB Output is correct
13 Correct 1 ms 1356 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
15 Correct 1 ms 844 KB Output is correct
16 Correct 2 ms 1356 KB Output is correct
17 Correct 1 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 2 ms 1356 KB Output is correct
7 Correct 1 ms 844 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1356 KB Output is correct
10 Correct 1 ms 292 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 1356 KB Output is correct
13 Correct 1 ms 1356 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
15 Correct 1 ms 844 KB Output is correct
16 Correct 2 ms 1356 KB Output is correct
17 Correct 1 ms 1356 KB Output is correct
18 Correct 1 ms 1744 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 2 ms 1356 KB Output is correct
21 Correct 2 ms 1740 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 1 ms 1868 KB Output is correct
24 Correct 2 ms 1612 KB Output is correct
25 Correct 2 ms 1740 KB Output is correct
26 Correct 2 ms 1740 KB Output is correct
27 Correct 2 ms 844 KB Output is correct
28 Correct 1 ms 972 KB Output is correct
29 Correct 2 ms 1876 KB Output is correct
30 Correct 3 ms 1868 KB Output is correct
31 Correct 1 ms 1740 KB Output is correct
32 Correct 1 ms 1612 KB Output is correct
33 Correct 1 ms 1868 KB Output is correct
34 Correct 2 ms 1872 KB Output is correct
35 Correct 2 ms 1872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 2 ms 1356 KB Output is correct
7 Correct 1 ms 844 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1356 KB Output is correct
10 Correct 1 ms 292 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 1356 KB Output is correct
13 Correct 1 ms 1356 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
15 Correct 1 ms 844 KB Output is correct
16 Correct 2 ms 1356 KB Output is correct
17 Correct 1 ms 1356 KB Output is correct
18 Correct 154 ms 207636 KB Output is correct
19 Correct 82 ms 126096 KB Output is correct
20 Correct 43 ms 67520 KB Output is correct
21 Correct 88 ms 119144 KB Output is correct
22 Correct 112 ms 154276 KB Output is correct
23 Correct 38 ms 57544 KB Output is correct
24 Correct 27 ms 44116 KB Output is correct
25 Correct 35 ms 55836 KB Output is correct
26 Correct 15 ms 20536 KB Output is correct
27 Correct 41 ms 58728 KB Output is correct
28 Correct 28 ms 41012 KB Output is correct
29 Correct 40 ms 59896 KB Output is correct
30 Correct 32 ms 46192 KB Output is correct
31 Correct 35 ms 55732 KB Output is correct
32 Correct 19 ms 28520 KB Output is correct
33 Correct 40 ms 55632 KB Output is correct
34 Correct 13 ms 19160 KB Output is correct
35 Correct 36 ms 54556 KB Output is correct
36 Correct 16 ms 25304 KB Output is correct
37 Correct 39 ms 58612 KB Output is correct
38 Correct 19 ms 31356 KB Output is correct
39 Correct 42 ms 61116 KB Output is correct
40 Correct 22 ms 34840 KB Output is correct
41 Correct 204 ms 255988 KB Output is correct
42 Correct 125 ms 172640 KB Output is correct
43 Correct 178 ms 256120 KB Output is correct
44 Correct 113 ms 170528 KB Output is correct
45 Correct 177 ms 255916 KB Output is correct
46 Correct 118 ms 172632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 2 ms 1356 KB Output is correct
7 Correct 1 ms 844 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1356 KB Output is correct
10 Correct 1 ms 292 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 1356 KB Output is correct
13 Correct 1 ms 1356 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
15 Correct 1 ms 844 KB Output is correct
16 Correct 2 ms 1356 KB Output is correct
17 Correct 1 ms 1356 KB Output is correct
18 Correct 1 ms 1744 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 2 ms 1356 KB Output is correct
21 Correct 2 ms 1740 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 1 ms 1868 KB Output is correct
24 Correct 2 ms 1612 KB Output is correct
25 Correct 2 ms 1740 KB Output is correct
26 Correct 2 ms 1740 KB Output is correct
27 Correct 2 ms 844 KB Output is correct
28 Correct 1 ms 972 KB Output is correct
29 Correct 2 ms 1876 KB Output is correct
30 Correct 3 ms 1868 KB Output is correct
31 Correct 1 ms 1740 KB Output is correct
32 Correct 1 ms 1612 KB Output is correct
33 Correct 1 ms 1868 KB Output is correct
34 Correct 2 ms 1872 KB Output is correct
35 Correct 2 ms 1872 KB Output is correct
36 Correct 154 ms 207636 KB Output is correct
37 Correct 82 ms 126096 KB Output is correct
38 Correct 43 ms 67520 KB Output is correct
39 Correct 88 ms 119144 KB Output is correct
40 Correct 112 ms 154276 KB Output is correct
41 Correct 38 ms 57544 KB Output is correct
42 Correct 27 ms 44116 KB Output is correct
43 Correct 35 ms 55836 KB Output is correct
44 Correct 15 ms 20536 KB Output is correct
45 Correct 41 ms 58728 KB Output is correct
46 Correct 28 ms 41012 KB Output is correct
47 Correct 40 ms 59896 KB Output is correct
48 Correct 32 ms 46192 KB Output is correct
49 Correct 35 ms 55732 KB Output is correct
50 Correct 19 ms 28520 KB Output is correct
51 Correct 40 ms 55632 KB Output is correct
52 Correct 13 ms 19160 KB Output is correct
53 Correct 36 ms 54556 KB Output is correct
54 Correct 16 ms 25304 KB Output is correct
55 Correct 39 ms 58612 KB Output is correct
56 Correct 19 ms 31356 KB Output is correct
57 Correct 42 ms 61116 KB Output is correct
58 Correct 22 ms 34840 KB Output is correct
59 Correct 204 ms 255988 KB Output is correct
60 Correct 125 ms 172640 KB Output is correct
61 Correct 178 ms 256120 KB Output is correct
62 Correct 113 ms 170528 KB Output is correct
63 Correct 177 ms 255916 KB Output is correct
64 Correct 118 ms 172632 KB Output is correct
65 Correct 166 ms 231160 KB Output is correct
66 Correct 145 ms 212160 KB Output is correct
67 Correct 138 ms 203064 KB Output is correct
68 Correct 139 ms 187536 KB Output is correct
69 Correct 153 ms 228684 KB Output is correct
70 Correct 157 ms 219208 KB Output is correct
71 Correct 152 ms 221604 KB Output is correct
72 Correct 150 ms 223952 KB Output is correct
73 Correct 144 ms 207628 KB Output is correct
74 Correct 130 ms 194120 KB Output is correct
75 Correct 140 ms 214632 KB Output is correct
76 Correct 170 ms 245780 KB Output is correct
77 Correct 171 ms 245780 KB Output is correct
78 Correct 126 ms 189672 KB Output is correct
79 Correct 136 ms 196376 KB Output is correct
80 Correct 168 ms 240860 KB Output is correct
81 Correct 135 ms 198528 KB Output is correct
82 Correct 135 ms 209948 KB Output is correct
83 Correct 179 ms 256000 KB Output is correct
84 Correct 138 ms 219200 KB Output is correct
85 Correct 156 ms 238384 KB Output is correct
86 Correct 151 ms 233608 KB Output is correct
87 Correct 141 ms 214548 KB Output is correct
88 Correct 171 ms 258244 KB Output is correct
89 Correct 177 ms 258404 KB Output is correct
90 Correct 161 ms 216844 KB Output is correct
91 Correct 168 ms 258324 KB Output is correct
92 Correct 174 ms 258416 KB Output is correct
93 Correct 176 ms 253508 KB Output is correct