# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
365236 | 2021-02-11T09:45:16 Z | Dymo | Collecting Stamps 3 (JOI20_ho_t3) | C++14 | 125 ms | 134124 KB |
#include<bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define ff first #define ss second #define pb push_back //#define endl "\n" const ll maxn =2e2+10; const ll mod=1e9+7; const ll base=1e18; ll dp[maxn][maxn][maxn][2]; ll x[maxn]; ll t[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (fopen("t.inp","r")) { freopen("test.inp","r",stdin); freopen("test.out","w",stdout); } ll n,l ; cin>>n>>l ; x[0]=0; 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; i++) { for (int j=0; j<=n; j++) { for (int k=0; k<=n; k++) { for (int t=0; t<=1; t++) dp[i][j][k][t]=base; } } } dp[0][0][0][0]=0; dp[0][0][0][1]=0; for (int len=1; len<=n; len++) { for (int j=0; j-len<0; j++) { ll nxt=j-len+1; if (nxt<0) nxt+=(n+1); for (int cnt=0; cnt<=n; cnt++) { // dp[nxt][j][cnt][0] ll kc=abs(x[nxt]-x[(nxt-1+(n+1))%(n+1)]); if (nxt==0) { kc=l-x[n]; } if (dp[nxt][j][cnt][0]+kc<=t[(nxt-1+(n+1))%(n+1)]) { dp[(nxt-1+(n+1))%(n+1)][j][cnt+1][0]=min(dp[(nxt-1+(n+1))%(n+1)][j][cnt+1][0],dp[nxt][j][cnt][0]+kc); } else { dp[(nxt-1+(n+1))%(n+1)][j][cnt][0]=min(dp[(nxt-1+(n+1))%(n+1)][j][cnt][0],dp[nxt][j][cnt][0]+kc); } kc=abs(x[nxt]-x[j+1]); if (nxt!=0) { kc=l-x[nxt]+x[j+1]; } if (dp[nxt][j][cnt][0]+kc<=t[j+1]) { dp[nxt][j+1][cnt+1][1]=min(dp[nxt][j+1][cnt+1][1],dp[nxt][j][cnt][0]+kc); } else { dp[nxt][j+1][cnt][1]=min(dp[nxt][j+1][cnt][1],dp[nxt][j][cnt][0]+kc); } // dp[nxt][j][cnt][1] kc=min(abs(x[j]-x[(nxt-1+(n+1))%(n+1)]),x[j]+l-x[(nxt-1+(n+1))%(n+1)]); if (nxt==0) { kc=l-x[n]+x[j]; } if (dp[nxt][j][cnt][1]+kc<=t[(nxt-1+(n+1))%(n+1)]) { dp[(nxt-1+(n+1))%(n+1)][j][cnt+1][0]=min(dp[(nxt-1+(n+1))%(n+1)][j][cnt+1][0],dp[nxt][j][cnt][1]+kc); } else { dp[(nxt-1+(n+1))%(n+1)][j][cnt][0]=min(dp[(nxt-1+(n+1))%(n+1)][j][cnt][0],dp[nxt][j][cnt][1]+kc); } kc=abs(x[j]-x[j+1]); if (dp[nxt][j][cnt][1]+kc<=t[j+1]) { dp[nxt][j+1][cnt+1][1]=min(dp[nxt][j+1][cnt+1][1],dp[nxt][j][cnt][1]+kc); } else { dp[nxt][j+1][cnt][1]=min(dp[nxt][j+1][cnt][1],dp[nxt][j][cnt][1]+kc); } } } } // cout <<dp[6][0][1][0]<<endl; // cout <<dp[5][0][2][0]<<endl; // cout <<dp[5][1][3][1]<<endl; ll ans=0; for (int i=0; i<=n; i++) { for (int j=0; j<=n; j++) { for (ll k=0; k<=n; k++) { for (int t=0; t<=1; t++) { if (dp[i][j][k][t]!=base) { ans=max(ans,k); } } } } } cout <<ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 1 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 768 KB | Output is correct |
4 | Correct | 1 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 620 KB | Output is correct |
6 | Correct | 1 ms | 876 KB | Output is correct |
7 | Correct | 1 ms | 620 KB | Output is correct |
8 | Correct | 1 ms | 748 KB | Output is correct |
9 | Correct | 1 ms | 876 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 876 KB | Output is correct |
13 | Correct | 1 ms | 876 KB | Output is correct |
14 | Correct | 1 ms | 620 KB | Output is correct |
15 | Correct | 1 ms | 620 KB | Output is correct |
16 | Correct | 1 ms | 876 KB | Output is correct |
17 | Correct | 1 ms | 912 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 1 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 768 KB | Output is correct |
4 | Correct | 1 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 620 KB | Output is correct |
6 | Correct | 1 ms | 876 KB | Output is correct |
7 | Correct | 1 ms | 620 KB | Output is correct |
8 | Correct | 1 ms | 748 KB | Output is correct |
9 | Correct | 1 ms | 876 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 876 KB | Output is correct |
13 | Correct | 1 ms | 876 KB | Output is correct |
14 | Correct | 1 ms | 620 KB | Output is correct |
15 | Correct | 1 ms | 620 KB | Output is correct |
16 | Correct | 1 ms | 876 KB | Output is correct |
17 | Correct | 1 ms | 912 KB | Output is correct |
18 | Correct | 1 ms | 1140 KB | Output is correct |
19 | Correct | 1 ms | 748 KB | Output is correct |
20 | Correct | 1 ms | 876 KB | Output is correct |
21 | Correct | 1 ms | 1132 KB | Output is correct |
22 | Correct | 1 ms | 620 KB | Output is correct |
23 | Correct | 1 ms | 1260 KB | Output is correct |
24 | Correct | 1 ms | 1004 KB | Output is correct |
25 | Correct | 1 ms | 1152 KB | Output is correct |
26 | Correct | 2 ms | 1164 KB | Output is correct |
27 | Correct | 1 ms | 620 KB | Output is correct |
28 | Correct | 1 ms | 620 KB | Output is correct |
29 | Correct | 1 ms | 1260 KB | Output is correct |
30 | Correct | 1 ms | 1260 KB | Output is correct |
31 | Correct | 1 ms | 1132 KB | Output is correct |
32 | Correct | 1 ms | 1024 KB | Output is correct |
33 | Correct | 1 ms | 1260 KB | Output is correct |
34 | Correct | 1 ms | 1260 KB | Output is correct |
35 | Correct | 2 ms | 1260 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 1 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 768 KB | Output is correct |
4 | Correct | 1 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 620 KB | Output is correct |
6 | Correct | 1 ms | 876 KB | Output is correct |
7 | Correct | 1 ms | 620 KB | Output is correct |
8 | Correct | 1 ms | 748 KB | Output is correct |
9 | Correct | 1 ms | 876 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 876 KB | Output is correct |
13 | Correct | 1 ms | 876 KB | Output is correct |
14 | Correct | 1 ms | 620 KB | Output is correct |
15 | Correct | 1 ms | 620 KB | Output is correct |
16 | Correct | 1 ms | 876 KB | Output is correct |
17 | Correct | 1 ms | 912 KB | Output is correct |
18 | Correct | 90 ms | 107628 KB | Output is correct |
19 | Correct | 54 ms | 65260 KB | Output is correct |
20 | Correct | 27 ms | 34924 KB | Output is correct |
21 | Correct | 50 ms | 61548 KB | Output is correct |
22 | Correct | 66 ms | 79888 KB | Output is correct |
23 | Correct | 23 ms | 29676 KB | Output is correct |
24 | Correct | 21 ms | 23276 KB | Output is correct |
25 | Correct | 23 ms | 29164 KB | Output is correct |
26 | Correct | 8 ms | 11116 KB | Output is correct |
27 | Correct | 24 ms | 30316 KB | Output is correct |
28 | Correct | 16 ms | 21612 KB | Output is correct |
29 | Correct | 24 ms | 30956 KB | Output is correct |
30 | Correct | 20 ms | 24300 KB | Output is correct |
31 | Correct | 23 ms | 29036 KB | Output is correct |
32 | Correct | 13 ms | 15212 KB | Output is correct |
33 | Correct | 22 ms | 29036 KB | Output is correct |
34 | Correct | 7 ms | 10476 KB | Output is correct |
35 | Correct | 21 ms | 28396 KB | Output is correct |
36 | Correct | 10 ms | 13548 KB | Output is correct |
37 | Correct | 23 ms | 30444 KB | Output is correct |
38 | Correct | 16 ms | 16620 KB | Output is correct |
39 | Correct | 29 ms | 31596 KB | Output is correct |
40 | Correct | 15 ms | 18540 KB | Output is correct |
41 | Correct | 109 ms | 132716 KB | Output is correct |
42 | Correct | 74 ms | 89452 KB | Output is correct |
43 | Correct | 110 ms | 132716 KB | Output is correct |
44 | Correct | 84 ms | 88300 KB | Output is correct |
45 | Correct | 120 ms | 132716 KB | Output is correct |
46 | Correct | 73 ms | 89324 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 1 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 768 KB | Output is correct |
4 | Correct | 1 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 620 KB | Output is correct |
6 | Correct | 1 ms | 876 KB | Output is correct |
7 | Correct | 1 ms | 620 KB | Output is correct |
8 | Correct | 1 ms | 748 KB | Output is correct |
9 | Correct | 1 ms | 876 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 876 KB | Output is correct |
13 | Correct | 1 ms | 876 KB | Output is correct |
14 | Correct | 1 ms | 620 KB | Output is correct |
15 | Correct | 1 ms | 620 KB | Output is correct |
16 | Correct | 1 ms | 876 KB | Output is correct |
17 | Correct | 1 ms | 912 KB | Output is correct |
18 | Correct | 1 ms | 1140 KB | Output is correct |
19 | Correct | 1 ms | 748 KB | Output is correct |
20 | Correct | 1 ms | 876 KB | Output is correct |
21 | Correct | 1 ms | 1132 KB | Output is correct |
22 | Correct | 1 ms | 620 KB | Output is correct |
23 | Correct | 1 ms | 1260 KB | Output is correct |
24 | Correct | 1 ms | 1004 KB | Output is correct |
25 | Correct | 1 ms | 1152 KB | Output is correct |
26 | Correct | 2 ms | 1164 KB | Output is correct |
27 | Correct | 1 ms | 620 KB | Output is correct |
28 | Correct | 1 ms | 620 KB | Output is correct |
29 | Correct | 1 ms | 1260 KB | Output is correct |
30 | Correct | 1 ms | 1260 KB | Output is correct |
31 | Correct | 1 ms | 1132 KB | Output is correct |
32 | Correct | 1 ms | 1024 KB | Output is correct |
33 | Correct | 1 ms | 1260 KB | Output is correct |
34 | Correct | 1 ms | 1260 KB | Output is correct |
35 | Correct | 2 ms | 1260 KB | Output is correct |
36 | Correct | 90 ms | 107628 KB | Output is correct |
37 | Correct | 54 ms | 65260 KB | Output is correct |
38 | Correct | 27 ms | 34924 KB | Output is correct |
39 | Correct | 50 ms | 61548 KB | Output is correct |
40 | Correct | 66 ms | 79888 KB | Output is correct |
41 | Correct | 23 ms | 29676 KB | Output is correct |
42 | Correct | 21 ms | 23276 KB | Output is correct |
43 | Correct | 23 ms | 29164 KB | Output is correct |
44 | Correct | 8 ms | 11116 KB | Output is correct |
45 | Correct | 24 ms | 30316 KB | Output is correct |
46 | Correct | 16 ms | 21612 KB | Output is correct |
47 | Correct | 24 ms | 30956 KB | Output is correct |
48 | Correct | 20 ms | 24300 KB | Output is correct |
49 | Correct | 23 ms | 29036 KB | Output is correct |
50 | Correct | 13 ms | 15212 KB | Output is correct |
51 | Correct | 22 ms | 29036 KB | Output is correct |
52 | Correct | 7 ms | 10476 KB | Output is correct |
53 | Correct | 21 ms | 28396 KB | Output is correct |
54 | Correct | 10 ms | 13548 KB | Output is correct |
55 | Correct | 23 ms | 30444 KB | Output is correct |
56 | Correct | 16 ms | 16620 KB | Output is correct |
57 | Correct | 29 ms | 31596 KB | Output is correct |
58 | Correct | 15 ms | 18540 KB | Output is correct |
59 | Correct | 109 ms | 132716 KB | Output is correct |
60 | Correct | 74 ms | 89452 KB | Output is correct |
61 | Correct | 110 ms | 132716 KB | Output is correct |
62 | Correct | 84 ms | 88300 KB | Output is correct |
63 | Correct | 120 ms | 132716 KB | Output is correct |
64 | Correct | 73 ms | 89324 KB | Output is correct |
65 | Correct | 99 ms | 119824 KB | Output is correct |
66 | Correct | 93 ms | 109932 KB | Output is correct |
67 | Correct | 96 ms | 105104 KB | Output is correct |
68 | Correct | 82 ms | 97132 KB | Output is correct |
69 | Correct | 99 ms | 118508 KB | Output is correct |
70 | Correct | 95 ms | 113516 KB | Output is correct |
71 | Correct | 96 ms | 114796 KB | Output is correct |
72 | Correct | 105 ms | 115948 KB | Output is correct |
73 | Correct | 93 ms | 107500 KB | Output is correct |
74 | Correct | 95 ms | 100460 KB | Output is correct |
75 | Correct | 93 ms | 111084 KB | Output is correct |
76 | Correct | 119 ms | 127340 KB | Output is correct |
77 | Correct | 111 ms | 127468 KB | Output is correct |
78 | Correct | 85 ms | 98284 KB | Output is correct |
79 | Correct | 85 ms | 101612 KB | Output is correct |
80 | Correct | 125 ms | 124908 KB | Output is correct |
81 | Correct | 87 ms | 102764 KB | Output is correct |
82 | Correct | 91 ms | 108780 KB | Output is correct |
83 | Correct | 116 ms | 132716 KB | Output is correct |
84 | Correct | 94 ms | 113516 KB | Output is correct |
85 | Correct | 103 ms | 123480 KB | Output is correct |
86 | Correct | 105 ms | 121068 KB | Output is correct |
87 | Correct | 95 ms | 111212 KB | Output is correct |
88 | Correct | 112 ms | 133928 KB | Output is correct |
89 | Correct | 112 ms | 134124 KB | Output is correct |
90 | Correct | 101 ms | 112364 KB | Output is correct |
91 | Correct | 114 ms | 133992 KB | Output is correct |
92 | Correct | 112 ms | 133996 KB | Output is correct |
93 | Correct | 109 ms | 131308 KB | Output is correct |