#include <bits/stdc++.h>
#define DIM 410
#define INF 2000000000000000000LL
using namespace std;
pair <int,long long> dp[DIM][DIM][2];
int viz[DIM][DIM][2],v[DIM],t[DIM];
struct idk{
int i,j,dir;
};
deque <idk> c;
int n,L,i,j;
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n>>L;
for (i=1;i<=n;i++)
cin>>v[i];
for (i=1;i<=n;i++)
cin>>t[i];
for (i=0;i<=n;i++)
for (j=0;j<=n;j++)
dp[i][j][0] = dp[i][j][1] = make_pair (0,INF);
/// dp[i][j][0/1] - nr maxim de timbre pe care le pot lua daca am parcurs i din stanga si j din dreapta
dp[0][0][0] = dp[0][0][1] = make_pair (0,0);
c.push_back({0,0,0});
viz[0][0][0] = 1;
c.push_back({0,0,1});
viz[0][0][1] = 1;
v[n+1] = L;
while (!c.empty()){
int i = c.front().i;
int j = c.front().j;
int dir = c.front().dir;
c.pop_front();
viz[i][j][dir] = 0;
long long timp = dp[i][j][dir].second + L - v[n-j+1] + v[i];
if (dir == 1){
int cnt = 0;
for (int poz=i+1;poz+j<=n;poz++){
timp += v[poz] - v[poz-1];
if (timp <= t[poz]){ /// as putea sa iau timbrul asta
cnt++;
if (dp[i][j][dir].first + cnt > dp[poz][j][0].first){
dp[poz][j][0].first = dp[i][j][dir].first + cnt;
dp[poz][j][0].second = timp;
} else {
if (dp[i][j][dir].first + cnt == dp[poz][j][0].first && timp < dp[poz][j][0].second)
dp[poz][j][0].second = timp;
}
if (dp[i][j][dir].first + cnt == dp[poz][j][0].first && !viz[poz][j][0]){
c.push_back({poz,j,0});
viz[poz][j][0] = 1;
}}}
} else {
int cnt = 0;
for (int poz=j+1;i+poz<=n;poz++){
timp += v[n-poz+2] - v[n-poz+1];
if (timp <= t[n-poz+1]){
cnt++;
if (dp[i][j][dir].first + cnt > dp[i][poz][1].first){
dp[i][poz][1].first = dp[i][j][dir].first + cnt;
dp[i][poz][1].second = timp;
} else {
if (dp[i][j][dir].first + cnt == dp[i][poz][1].first && timp < dp[i][poz][1].second)
dp[i][poz][1].second = timp;
}
if (dp[i][j][dir].first + cnt == dp[i][poz][1].first && !viz[i][poz][1]){
c.push_back({i,poz,1});
viz[i][poz][1] = 1;
}}}}}
int sol = 0;
for (i=0;i<=n;i++)
for (j=0;j<=n;j++)
sol = max (sol,max(dp[i][j][0].first,dp[i][j][1].first));
cout<<sol;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
512 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
512 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
512 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
512 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
256 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
512 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
10 ms |
2432 KB |
Output is correct |
19 |
Correct |
8 ms |
1920 KB |
Output is correct |
20 |
Correct |
6 ms |
1280 KB |
Output is correct |
21 |
Correct |
8 ms |
1792 KB |
Output is correct |
22 |
Correct |
8 ms |
2048 KB |
Output is correct |
23 |
Correct |
11 ms |
1280 KB |
Output is correct |
24 |
Correct |
5 ms |
896 KB |
Output is correct |
25 |
Correct |
11 ms |
1280 KB |
Output is correct |
26 |
Correct |
5 ms |
640 KB |
Output is correct |
27 |
Correct |
12 ms |
1280 KB |
Output is correct |
28 |
Correct |
5 ms |
1024 KB |
Output is correct |
29 |
Correct |
6 ms |
1280 KB |
Output is correct |
30 |
Correct |
5 ms |
896 KB |
Output is correct |
31 |
Correct |
6 ms |
1152 KB |
Output is correct |
32 |
Correct |
5 ms |
896 KB |
Output is correct |
33 |
Correct |
6 ms |
1152 KB |
Output is correct |
34 |
Correct |
5 ms |
640 KB |
Output is correct |
35 |
Correct |
5 ms |
1024 KB |
Output is correct |
36 |
Correct |
5 ms |
768 KB |
Output is correct |
37 |
Correct |
5 ms |
1024 KB |
Output is correct |
38 |
Correct |
5 ms |
896 KB |
Output is correct |
39 |
Correct |
5 ms |
1024 KB |
Output is correct |
40 |
Correct |
5 ms |
768 KB |
Output is correct |
41 |
Correct |
29 ms |
3072 KB |
Output is correct |
42 |
Correct |
6 ms |
1792 KB |
Output is correct |
43 |
Correct |
26 ms |
3072 KB |
Output is correct |
44 |
Correct |
5 ms |
1792 KB |
Output is correct |
45 |
Correct |
26 ms |
3072 KB |
Output is correct |
46 |
Correct |
6 ms |
1792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
512 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
512 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
512 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
256 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
10 ms |
2432 KB |
Output is correct |
37 |
Correct |
8 ms |
1920 KB |
Output is correct |
38 |
Correct |
6 ms |
1280 KB |
Output is correct |
39 |
Correct |
8 ms |
1792 KB |
Output is correct |
40 |
Correct |
8 ms |
2048 KB |
Output is correct |
41 |
Correct |
11 ms |
1280 KB |
Output is correct |
42 |
Correct |
5 ms |
896 KB |
Output is correct |
43 |
Correct |
11 ms |
1280 KB |
Output is correct |
44 |
Correct |
5 ms |
640 KB |
Output is correct |
45 |
Correct |
12 ms |
1280 KB |
Output is correct |
46 |
Correct |
5 ms |
1024 KB |
Output is correct |
47 |
Correct |
6 ms |
1280 KB |
Output is correct |
48 |
Correct |
5 ms |
896 KB |
Output is correct |
49 |
Correct |
6 ms |
1152 KB |
Output is correct |
50 |
Correct |
5 ms |
896 KB |
Output is correct |
51 |
Correct |
6 ms |
1152 KB |
Output is correct |
52 |
Correct |
5 ms |
640 KB |
Output is correct |
53 |
Correct |
5 ms |
1024 KB |
Output is correct |
54 |
Correct |
5 ms |
768 KB |
Output is correct |
55 |
Correct |
5 ms |
1024 KB |
Output is correct |
56 |
Correct |
5 ms |
896 KB |
Output is correct |
57 |
Correct |
5 ms |
1024 KB |
Output is correct |
58 |
Correct |
5 ms |
768 KB |
Output is correct |
59 |
Correct |
29 ms |
3072 KB |
Output is correct |
60 |
Correct |
6 ms |
1792 KB |
Output is correct |
61 |
Correct |
26 ms |
3072 KB |
Output is correct |
62 |
Correct |
5 ms |
1792 KB |
Output is correct |
63 |
Correct |
26 ms |
3072 KB |
Output is correct |
64 |
Correct |
6 ms |
1792 KB |
Output is correct |
65 |
Correct |
10 ms |
2688 KB |
Output is correct |
66 |
Correct |
11 ms |
2560 KB |
Output is correct |
67 |
Correct |
10 ms |
2432 KB |
Output is correct |
68 |
Correct |
10 ms |
2304 KB |
Output is correct |
69 |
Correct |
10 ms |
2688 KB |
Output is correct |
70 |
Correct |
99 ms |
2944 KB |
Output is correct |
71 |
Correct |
6 ms |
2304 KB |
Output is correct |
72 |
Correct |
100 ms |
2944 KB |
Output is correct |
73 |
Correct |
6 ms |
2432 KB |
Output is correct |
74 |
Correct |
82 ms |
2688 KB |
Output is correct |
75 |
Correct |
6 ms |
2304 KB |
Output is correct |
76 |
Correct |
43 ms |
2816 KB |
Output is correct |
77 |
Correct |
6 ms |
2560 KB |
Output is correct |
78 |
Correct |
34 ms |
2304 KB |
Output is correct |
79 |
Correct |
6 ms |
2304 KB |
Output is correct |
80 |
Correct |
50 ms |
2816 KB |
Output is correct |
81 |
Correct |
6 ms |
2304 KB |
Output is correct |
82 |
Correct |
8 ms |
2304 KB |
Output is correct |
83 |
Correct |
6 ms |
2688 KB |
Output is correct |
84 |
Correct |
9 ms |
2304 KB |
Output is correct |
85 |
Correct |
6 ms |
2688 KB |
Output is correct |
86 |
Correct |
9 ms |
2432 KB |
Output is correct |
87 |
Correct |
6 ms |
2560 KB |
Output is correct |
88 |
Correct |
26 ms |
3320 KB |
Output is correct |
89 |
Correct |
26 ms |
3072 KB |
Output is correct |
90 |
Correct |
6 ms |
2048 KB |
Output is correct |
91 |
Correct |
29 ms |
3200 KB |
Output is correct |
92 |
Correct |
30 ms |
3072 KB |
Output is correct |
93 |
Correct |
6 ms |
2304 KB |
Output is correct |