#include <bits/stdc++.h>
#pragma optimize GCC ("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
///#include <tryhardmode>
///#include <GODMODE::ON>
using namespace std;
///What a day...
///You look lonely, I can fix that
const long long INF=1e18;
const int NMAX=305;
#define int long long
int dp[NMAX][NMAX][NMAX][2]; ///minimum time -> clock, counter-clock, answer, direction (0->clock, 1->counter-clock)
int x[NMAX];
int t[NMAX];
int l;
int get_dist(int a,int b)
{
///I got guns in my head and they won't go,
///Spirits in my head and they won't go...
if(a>b)
swap(a,b);
return min(x[b]-x[a],l-x[b]+x[a]);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,i,j,k,st,dr,ans,best=0;
cin>>n>>l;
for(i=1;i<=n;i++)
cin>>x[i];
x[n+1]=l;
for(i=1;i<=n;i++)
cin>>t[i];
for(i=0;i<=n+1;i++)
for(j=0;j<=n+1;j++)
for(k=0;k<=n+1;k++)
dp[i][j][k][0]=dp[i][j][k][1]=INF;
dp[0][0][0][0]=0,dp[0][0][0][1]=0;
for(st=0;st<=n;st++)
{
for(dr=0;dr<=n;dr++)
{
if(st+dr>n)
break;
for(ans=0;ans<=n;ans++)
{
if(st+1<=n)
{
long long auxy=dp[st][dr][ans][1]+get_dist(n+1-dr,st+1);
auxy=min(auxy,dp[st][dr][ans][0]+get_dist(st,st+1));
if(auxy<=t[st+1])
{
if(ans+1>n)
continue;
dp[st+1][dr][ans+1][0]=min(dp[st+1][dr][ans+1][0],auxy);
best=max(best,ans+1);
}
else
dp[st+1][dr][ans][0]=min(dp[st+1][dr][ans][0],auxy);
}
if(dr+1<=n)
{
if(n+1-dr-1==0 || n+1-dr-1==n+1)
continue;
long long auxy=dp[st][dr][ans][1]+get_dist(n+1-dr,n+1-dr-1);
auxy=min(auxy,dp[st][dr][ans][0]+get_dist(st,n+1-dr-1));
if(auxy<=t[n+1-dr-1])
{
if(ans+1>n)
continue;
dp[st][dr+1][ans+1][1]=min(dp[st][dr+1][ans+1][1],auxy);
best=max(best,ans+1);
}
else
dp[st][dr+1][ans][1]=min(dp[st][dr+1][ans][1],auxy);
}
}
}
}
for(ans=n;ans>=0;ans--)
{
for(st=0;st<=n;st++)
{
dr=n-st;
if(dp[st][dr][ans][0]<INF || dp[st][dr][ans][1]<INF)
{
cout<<ans;
exit(0);
}
}
}
return 0;
}
Compilation message
ho_t3.cpp:3: warning: ignoring '#pragma optimize GCC' [-Wunknown-pragmas]
3 | #pragma optimize GCC ("Ofast")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
5 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
12792 KB |
Output is correct |
6 |
Correct |
6 ms |
20824 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
3 ms |
16732 KB |
Output is correct |
9 |
Correct |
3 ms |
20828 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
3 ms |
20828 KB |
Output is correct |
13 |
Correct |
2 ms |
20828 KB |
Output is correct |
14 |
Correct |
2 ms |
12636 KB |
Output is correct |
15 |
Correct |
2 ms |
14684 KB |
Output is correct |
16 |
Correct |
4 ms |
20828 KB |
Output is correct |
17 |
Correct |
4 ms |
20828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
5 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
12792 KB |
Output is correct |
6 |
Correct |
6 ms |
20824 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
3 ms |
16732 KB |
Output is correct |
9 |
Correct |
3 ms |
20828 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
3 ms |
20828 KB |
Output is correct |
13 |
Correct |
2 ms |
20828 KB |
Output is correct |
14 |
Correct |
2 ms |
12636 KB |
Output is correct |
15 |
Correct |
2 ms |
14684 KB |
Output is correct |
16 |
Correct |
4 ms |
20828 KB |
Output is correct |
17 |
Correct |
4 ms |
20828 KB |
Output is correct |
18 |
Correct |
4 ms |
22876 KB |
Output is correct |
19 |
Correct |
3 ms |
16732 KB |
Output is correct |
20 |
Correct |
3 ms |
20828 KB |
Output is correct |
21 |
Correct |
3 ms |
22876 KB |
Output is correct |
22 |
Correct |
2 ms |
16732 KB |
Output is correct |
23 |
Correct |
4 ms |
25156 KB |
Output is correct |
24 |
Correct |
3 ms |
20828 KB |
Output is correct |
25 |
Correct |
3 ms |
22876 KB |
Output is correct |
26 |
Correct |
3 ms |
22876 KB |
Output is correct |
27 |
Correct |
2 ms |
14684 KB |
Output is correct |
28 |
Correct |
2 ms |
16732 KB |
Output is correct |
29 |
Correct |
3 ms |
24920 KB |
Output is correct |
30 |
Correct |
5 ms |
24924 KB |
Output is correct |
31 |
Correct |
3 ms |
22876 KB |
Output is correct |
32 |
Correct |
3 ms |
20828 KB |
Output is correct |
33 |
Correct |
3 ms |
24924 KB |
Output is correct |
34 |
Correct |
3 ms |
24924 KB |
Output is correct |
35 |
Correct |
3 ms |
25176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
5 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
12792 KB |
Output is correct |
6 |
Correct |
6 ms |
20824 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
3 ms |
16732 KB |
Output is correct |
9 |
Correct |
3 ms |
20828 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
3 ms |
20828 KB |
Output is correct |
13 |
Correct |
2 ms |
20828 KB |
Output is correct |
14 |
Correct |
2 ms |
12636 KB |
Output is correct |
15 |
Correct |
2 ms |
14684 KB |
Output is correct |
16 |
Correct |
4 ms |
20828 KB |
Output is correct |
17 |
Correct |
4 ms |
20828 KB |
Output is correct |
18 |
Correct |
101 ms |
202008 KB |
Output is correct |
19 |
Correct |
38 ms |
154968 KB |
Output is correct |
20 |
Correct |
22 ms |
124252 KB |
Output is correct |
21 |
Correct |
35 ms |
151284 KB |
Output is correct |
22 |
Correct |
47 ms |
170956 KB |
Output is correct |
23 |
Correct |
19 ms |
118364 KB |
Output is correct |
24 |
Correct |
16 ms |
114264 KB |
Output is correct |
25 |
Correct |
20 ms |
119132 KB |
Output is correct |
26 |
Correct |
11 ms |
84572 KB |
Output is correct |
27 |
Correct |
19 ms |
123152 KB |
Output is correct |
28 |
Correct |
15 ms |
114776 KB |
Output is correct |
29 |
Correct |
20 ms |
122196 KB |
Output is correct |
30 |
Correct |
17 ms |
118364 KB |
Output is correct |
31 |
Correct |
21 ms |
122492 KB |
Output is correct |
32 |
Correct |
13 ms |
98908 KB |
Output is correct |
33 |
Correct |
19 ms |
122064 KB |
Output is correct |
34 |
Correct |
10 ms |
82524 KB |
Output is correct |
35 |
Correct |
18 ms |
120188 KB |
Output is correct |
36 |
Correct |
12 ms |
92764 KB |
Output is correct |
37 |
Correct |
19 ms |
120300 KB |
Output is correct |
38 |
Correct |
13 ms |
103004 KB |
Output is correct |
39 |
Correct |
19 ms |
121436 KB |
Output is correct |
40 |
Correct |
14 ms |
109148 KB |
Output is correct |
41 |
Correct |
92 ms |
231948 KB |
Output is correct |
42 |
Correct |
61 ms |
191808 KB |
Output is correct |
43 |
Correct |
80 ms |
239700 KB |
Output is correct |
44 |
Correct |
52 ms |
190552 KB |
Output is correct |
45 |
Correct |
79 ms |
238908 KB |
Output is correct |
46 |
Correct |
51 ms |
192604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
5 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
12792 KB |
Output is correct |
6 |
Correct |
6 ms |
20824 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
3 ms |
16732 KB |
Output is correct |
9 |
Correct |
3 ms |
20828 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
3 ms |
20828 KB |
Output is correct |
13 |
Correct |
2 ms |
20828 KB |
Output is correct |
14 |
Correct |
2 ms |
12636 KB |
Output is correct |
15 |
Correct |
2 ms |
14684 KB |
Output is correct |
16 |
Correct |
4 ms |
20828 KB |
Output is correct |
17 |
Correct |
4 ms |
20828 KB |
Output is correct |
18 |
Correct |
4 ms |
22876 KB |
Output is correct |
19 |
Correct |
3 ms |
16732 KB |
Output is correct |
20 |
Correct |
3 ms |
20828 KB |
Output is correct |
21 |
Correct |
3 ms |
22876 KB |
Output is correct |
22 |
Correct |
2 ms |
16732 KB |
Output is correct |
23 |
Correct |
4 ms |
25156 KB |
Output is correct |
24 |
Correct |
3 ms |
20828 KB |
Output is correct |
25 |
Correct |
3 ms |
22876 KB |
Output is correct |
26 |
Correct |
3 ms |
22876 KB |
Output is correct |
27 |
Correct |
2 ms |
14684 KB |
Output is correct |
28 |
Correct |
2 ms |
16732 KB |
Output is correct |
29 |
Correct |
3 ms |
24920 KB |
Output is correct |
30 |
Correct |
5 ms |
24924 KB |
Output is correct |
31 |
Correct |
3 ms |
22876 KB |
Output is correct |
32 |
Correct |
3 ms |
20828 KB |
Output is correct |
33 |
Correct |
3 ms |
24924 KB |
Output is correct |
34 |
Correct |
3 ms |
24924 KB |
Output is correct |
35 |
Correct |
3 ms |
25176 KB |
Output is correct |
36 |
Correct |
101 ms |
202008 KB |
Output is correct |
37 |
Correct |
38 ms |
154968 KB |
Output is correct |
38 |
Correct |
22 ms |
124252 KB |
Output is correct |
39 |
Correct |
35 ms |
151284 KB |
Output is correct |
40 |
Correct |
47 ms |
170956 KB |
Output is correct |
41 |
Correct |
19 ms |
118364 KB |
Output is correct |
42 |
Correct |
16 ms |
114264 KB |
Output is correct |
43 |
Correct |
20 ms |
119132 KB |
Output is correct |
44 |
Correct |
11 ms |
84572 KB |
Output is correct |
45 |
Correct |
19 ms |
123152 KB |
Output is correct |
46 |
Correct |
15 ms |
114776 KB |
Output is correct |
47 |
Correct |
20 ms |
122196 KB |
Output is correct |
48 |
Correct |
17 ms |
118364 KB |
Output is correct |
49 |
Correct |
21 ms |
122492 KB |
Output is correct |
50 |
Correct |
13 ms |
98908 KB |
Output is correct |
51 |
Correct |
19 ms |
122064 KB |
Output is correct |
52 |
Correct |
10 ms |
82524 KB |
Output is correct |
53 |
Correct |
18 ms |
120188 KB |
Output is correct |
54 |
Correct |
12 ms |
92764 KB |
Output is correct |
55 |
Correct |
19 ms |
120300 KB |
Output is correct |
56 |
Correct |
13 ms |
103004 KB |
Output is correct |
57 |
Correct |
19 ms |
121436 KB |
Output is correct |
58 |
Correct |
14 ms |
109148 KB |
Output is correct |
59 |
Correct |
92 ms |
231948 KB |
Output is correct |
60 |
Correct |
61 ms |
191808 KB |
Output is correct |
61 |
Correct |
80 ms |
239700 KB |
Output is correct |
62 |
Correct |
52 ms |
190552 KB |
Output is correct |
63 |
Correct |
79 ms |
238908 KB |
Output is correct |
64 |
Correct |
51 ms |
192604 KB |
Output is correct |
65 |
Correct |
72 ms |
224356 KB |
Output is correct |
66 |
Correct |
65 ms |
214680 KB |
Output is correct |
67 |
Correct |
70 ms |
209492 KB |
Output is correct |
68 |
Correct |
59 ms |
200796 KB |
Output is correct |
69 |
Correct |
70 ms |
223056 KB |
Output is correct |
70 |
Correct |
71 ms |
217780 KB |
Output is correct |
71 |
Correct |
68 ms |
219980 KB |
Output is correct |
72 |
Correct |
70 ms |
220244 KB |
Output is correct |
73 |
Correct |
68 ms |
212052 KB |
Output is correct |
74 |
Correct |
59 ms |
204624 KB |
Output is correct |
75 |
Correct |
67 ms |
215128 KB |
Output is correct |
76 |
Correct |
82 ms |
233116 KB |
Output is correct |
77 |
Correct |
79 ms |
233252 KB |
Output is correct |
78 |
Correct |
58 ms |
202068 KB |
Output is correct |
79 |
Correct |
59 ms |
205656 KB |
Output is correct |
80 |
Correct |
76 ms |
230996 KB |
Output is correct |
81 |
Correct |
60 ms |
206020 KB |
Output is correct |
82 |
Correct |
65 ms |
213332 KB |
Output is correct |
83 |
Correct |
80 ms |
239696 KB |
Output is correct |
84 |
Correct |
69 ms |
217792 KB |
Output is correct |
85 |
Correct |
82 ms |
229716 KB |
Output is correct |
86 |
Correct |
80 ms |
225872 KB |
Output is correct |
87 |
Correct |
67 ms |
215120 KB |
Output is correct |
88 |
Correct |
81 ms |
240464 KB |
Output is correct |
89 |
Correct |
89 ms |
240292 KB |
Output is correct |
90 |
Correct |
70 ms |
216404 KB |
Output is correct |
91 |
Correct |
83 ms |
240468 KB |
Output is correct |
92 |
Correct |
79 ms |
241244 KB |
Output is correct |
93 |
Correct |
79 ms |
238264 KB |
Output is correct |