#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
int dp[202][202][202][2];
const int LEFT_SIDE = 0, RIGHT_SIDE = 1;
// posG, posD, nbStamps, side ==> temps min.
/////CHECK if posG+posD < N
signed main()
{
for(int pG = 0; pG< 202; pG++)
{
for(int pD = 0; pD < 202; pD++)
{
for(int nbStamps = 0; nbStamps < 202; nbStamps++)
{
dp[pG][pD][nbStamps][0] = INF;
dp[pG][pD][nbStamps][1] = INF;
}
}
}
dp[0][0][0][0] = dp[0][0][0][1] = 0;
int N, lacLen;
scanf("%lld%lld", &N, &lacLen);
vector<int > posLeft(N+1);
vector<int > expTimeLeft(N+1);
vector<int > posRight(N+1);
vector<int > expTimeRight(N+1);
for(int iS = 1, iR = N; iS <= N; iS++, iR--)
{
int posAct;
scanf("%lld", &posAct);
posLeft[iS] = posAct;
posRight[iR] = lacLen-posAct;
}
for(int iS = 1, iR = N; iS <= N; iS++, iR--)
{
int expTimeAct;
scanf("%lld", &expTimeAct);
expTimeLeft[iS] = expTimeAct;
expTimeRight[iR] = expTimeAct;
}
/*for(int i= 1; i<=N; i++)
{
printf("%lld/%lld ", posLeft[i], expTimeLeft[i]);
}
printf("\n");
for(int i= 1; i<=N; i++)
{
printf("%lld/%lld ", posRight[i], expTimeRight[i]);
}
printf("\n");*/
int ans = 0;
for(int nbStampsGot = 0; nbStampsGot <= N; nbStampsGot++)
{
for(int pL = 0; pL <= N; pL++)
{
for(int pR = 0; pR <= N - pL-1; pR++)/////////////////////////
{
for(int side = 0; side < 2; side ++)
{
if(dp[pL][pR][nbStampsGot][side] == INF)
continue;
int tpsBefore = dp[pL][pR][nbStampsGot][side];
int tpsGauche, tpsDroite;
if(side == LEFT_SIDE)
{
tpsGauche = tpsBefore + abs(posLeft[pL+1] - posLeft[pL]);////////////////
tpsDroite = tpsBefore + posLeft[pL] + posRight[pR+1];////////////////
}
else
{
tpsGauche = tpsBefore + posRight[pR] + posLeft[pL+1];
tpsDroite = tpsBefore + abs(posRight[pR+1] - posRight[pR]);
}
if(tpsGauche <= expTimeLeft[pL +1])
{
dp[pL+1][pR][nbStampsGot+1][LEFT_SIDE] = min(dp[pL+1][pR][nbStampsGot+1][LEFT_SIDE], tpsGauche);
ans = max(ans, nbStampsGot+1);
}
else
{
dp[pL+1][pR][nbStampsGot][LEFT_SIDE] = min(dp[pL+1][pR][nbStampsGot][LEFT_SIDE], tpsGauche);
}
if(tpsDroite <= expTimeRight[pR +1])
{
dp[pL][pR+1][nbStampsGot+1][RIGHT_SIDE] = min(dp[pL][pR+1][nbStampsGot+1][RIGHT_SIDE], tpsDroite);
ans = max(ans, nbStampsGot+1);
}
else
{
dp[pL][pR+1][nbStampsGot][RIGHT_SIDE] = min(dp[pL][pR+1][nbStampsGot][RIGHT_SIDE], tpsDroite);
}
}
}
}
}
printf("%lld\n", ans);
}
Compilation message
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | scanf("%lld%lld", &N, &lacLen);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | scanf("%lld", &posAct);
| ~~~~~^~~~~~~~~~~~~~~~~
ho_t3.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%lld", &expTimeAct);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
129224 KB |
Output is correct |
2 |
Correct |
48 ms |
129300 KB |
Output is correct |
3 |
Correct |
55 ms |
129228 KB |
Output is correct |
4 |
Correct |
54 ms |
129208 KB |
Output is correct |
5 |
Correct |
48 ms |
129232 KB |
Output is correct |
6 |
Correct |
46 ms |
129320 KB |
Output is correct |
7 |
Correct |
48 ms |
129204 KB |
Output is correct |
8 |
Correct |
47 ms |
129292 KB |
Output is correct |
9 |
Correct |
47 ms |
129304 KB |
Output is correct |
10 |
Correct |
51 ms |
129324 KB |
Output is correct |
11 |
Correct |
48 ms |
129236 KB |
Output is correct |
12 |
Correct |
50 ms |
129252 KB |
Output is correct |
13 |
Correct |
54 ms |
129228 KB |
Output is correct |
14 |
Correct |
46 ms |
129328 KB |
Output is correct |
15 |
Correct |
47 ms |
129204 KB |
Output is correct |
16 |
Correct |
46 ms |
129216 KB |
Output is correct |
17 |
Correct |
47 ms |
129312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
129224 KB |
Output is correct |
2 |
Correct |
48 ms |
129300 KB |
Output is correct |
3 |
Correct |
55 ms |
129228 KB |
Output is correct |
4 |
Correct |
54 ms |
129208 KB |
Output is correct |
5 |
Correct |
48 ms |
129232 KB |
Output is correct |
6 |
Correct |
46 ms |
129320 KB |
Output is correct |
7 |
Correct |
48 ms |
129204 KB |
Output is correct |
8 |
Correct |
47 ms |
129292 KB |
Output is correct |
9 |
Correct |
47 ms |
129304 KB |
Output is correct |
10 |
Correct |
51 ms |
129324 KB |
Output is correct |
11 |
Correct |
48 ms |
129236 KB |
Output is correct |
12 |
Correct |
50 ms |
129252 KB |
Output is correct |
13 |
Correct |
54 ms |
129228 KB |
Output is correct |
14 |
Correct |
46 ms |
129328 KB |
Output is correct |
15 |
Correct |
47 ms |
129204 KB |
Output is correct |
16 |
Correct |
46 ms |
129216 KB |
Output is correct |
17 |
Correct |
47 ms |
129312 KB |
Output is correct |
18 |
Correct |
47 ms |
129228 KB |
Output is correct |
19 |
Correct |
48 ms |
129328 KB |
Output is correct |
20 |
Correct |
48 ms |
129212 KB |
Output is correct |
21 |
Correct |
46 ms |
129224 KB |
Output is correct |
22 |
Correct |
46 ms |
129228 KB |
Output is correct |
23 |
Correct |
47 ms |
129232 KB |
Output is correct |
24 |
Correct |
47 ms |
129212 KB |
Output is correct |
25 |
Correct |
46 ms |
129320 KB |
Output is correct |
26 |
Correct |
48 ms |
129384 KB |
Output is correct |
27 |
Correct |
46 ms |
129288 KB |
Output is correct |
28 |
Correct |
46 ms |
129204 KB |
Output is correct |
29 |
Correct |
46 ms |
129324 KB |
Output is correct |
30 |
Correct |
45 ms |
129228 KB |
Output is correct |
31 |
Correct |
45 ms |
129276 KB |
Output is correct |
32 |
Correct |
46 ms |
129228 KB |
Output is correct |
33 |
Correct |
46 ms |
129260 KB |
Output is correct |
34 |
Correct |
48 ms |
129228 KB |
Output is correct |
35 |
Correct |
48 ms |
129312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
129224 KB |
Output is correct |
2 |
Correct |
48 ms |
129300 KB |
Output is correct |
3 |
Correct |
55 ms |
129228 KB |
Output is correct |
4 |
Correct |
54 ms |
129208 KB |
Output is correct |
5 |
Correct |
48 ms |
129232 KB |
Output is correct |
6 |
Correct |
46 ms |
129320 KB |
Output is correct |
7 |
Correct |
48 ms |
129204 KB |
Output is correct |
8 |
Correct |
47 ms |
129292 KB |
Output is correct |
9 |
Correct |
47 ms |
129304 KB |
Output is correct |
10 |
Correct |
51 ms |
129324 KB |
Output is correct |
11 |
Correct |
48 ms |
129236 KB |
Output is correct |
12 |
Correct |
50 ms |
129252 KB |
Output is correct |
13 |
Correct |
54 ms |
129228 KB |
Output is correct |
14 |
Correct |
46 ms |
129328 KB |
Output is correct |
15 |
Correct |
47 ms |
129204 KB |
Output is correct |
16 |
Correct |
46 ms |
129216 KB |
Output is correct |
17 |
Correct |
47 ms |
129312 KB |
Output is correct |
18 |
Correct |
77 ms |
129324 KB |
Output is correct |
19 |
Correct |
61 ms |
129308 KB |
Output is correct |
20 |
Correct |
54 ms |
129244 KB |
Output is correct |
21 |
Correct |
62 ms |
129220 KB |
Output is correct |
22 |
Correct |
68 ms |
129320 KB |
Output is correct |
23 |
Correct |
52 ms |
129228 KB |
Output is correct |
24 |
Correct |
50 ms |
129296 KB |
Output is correct |
25 |
Correct |
53 ms |
129328 KB |
Output is correct |
26 |
Correct |
48 ms |
129200 KB |
Output is correct |
27 |
Correct |
54 ms |
129228 KB |
Output is correct |
28 |
Correct |
51 ms |
129304 KB |
Output is correct |
29 |
Correct |
56 ms |
129436 KB |
Output is correct |
30 |
Correct |
50 ms |
129228 KB |
Output is correct |
31 |
Correct |
51 ms |
129224 KB |
Output is correct |
32 |
Correct |
49 ms |
129224 KB |
Output is correct |
33 |
Correct |
51 ms |
129244 KB |
Output is correct |
34 |
Correct |
48 ms |
129224 KB |
Output is correct |
35 |
Correct |
52 ms |
129228 KB |
Output is correct |
36 |
Correct |
49 ms |
129228 KB |
Output is correct |
37 |
Correct |
51 ms |
129228 KB |
Output is correct |
38 |
Correct |
49 ms |
129212 KB |
Output is correct |
39 |
Correct |
52 ms |
129256 KB |
Output is correct |
40 |
Correct |
50 ms |
129320 KB |
Output is correct |
41 |
Correct |
91 ms |
129340 KB |
Output is correct |
42 |
Correct |
70 ms |
129216 KB |
Output is correct |
43 |
Correct |
91 ms |
129332 KB |
Output is correct |
44 |
Correct |
72 ms |
129420 KB |
Output is correct |
45 |
Correct |
92 ms |
129332 KB |
Output is correct |
46 |
Correct |
71 ms |
129320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
129224 KB |
Output is correct |
2 |
Correct |
48 ms |
129300 KB |
Output is correct |
3 |
Correct |
55 ms |
129228 KB |
Output is correct |
4 |
Correct |
54 ms |
129208 KB |
Output is correct |
5 |
Correct |
48 ms |
129232 KB |
Output is correct |
6 |
Correct |
46 ms |
129320 KB |
Output is correct |
7 |
Correct |
48 ms |
129204 KB |
Output is correct |
8 |
Correct |
47 ms |
129292 KB |
Output is correct |
9 |
Correct |
47 ms |
129304 KB |
Output is correct |
10 |
Correct |
51 ms |
129324 KB |
Output is correct |
11 |
Correct |
48 ms |
129236 KB |
Output is correct |
12 |
Correct |
50 ms |
129252 KB |
Output is correct |
13 |
Correct |
54 ms |
129228 KB |
Output is correct |
14 |
Correct |
46 ms |
129328 KB |
Output is correct |
15 |
Correct |
47 ms |
129204 KB |
Output is correct |
16 |
Correct |
46 ms |
129216 KB |
Output is correct |
17 |
Correct |
47 ms |
129312 KB |
Output is correct |
18 |
Correct |
47 ms |
129228 KB |
Output is correct |
19 |
Correct |
48 ms |
129328 KB |
Output is correct |
20 |
Correct |
48 ms |
129212 KB |
Output is correct |
21 |
Correct |
46 ms |
129224 KB |
Output is correct |
22 |
Correct |
46 ms |
129228 KB |
Output is correct |
23 |
Correct |
47 ms |
129232 KB |
Output is correct |
24 |
Correct |
47 ms |
129212 KB |
Output is correct |
25 |
Correct |
46 ms |
129320 KB |
Output is correct |
26 |
Correct |
48 ms |
129384 KB |
Output is correct |
27 |
Correct |
46 ms |
129288 KB |
Output is correct |
28 |
Correct |
46 ms |
129204 KB |
Output is correct |
29 |
Correct |
46 ms |
129324 KB |
Output is correct |
30 |
Correct |
45 ms |
129228 KB |
Output is correct |
31 |
Correct |
45 ms |
129276 KB |
Output is correct |
32 |
Correct |
46 ms |
129228 KB |
Output is correct |
33 |
Correct |
46 ms |
129260 KB |
Output is correct |
34 |
Correct |
48 ms |
129228 KB |
Output is correct |
35 |
Correct |
48 ms |
129312 KB |
Output is correct |
36 |
Correct |
77 ms |
129324 KB |
Output is correct |
37 |
Correct |
61 ms |
129308 KB |
Output is correct |
38 |
Correct |
54 ms |
129244 KB |
Output is correct |
39 |
Correct |
62 ms |
129220 KB |
Output is correct |
40 |
Correct |
68 ms |
129320 KB |
Output is correct |
41 |
Correct |
52 ms |
129228 KB |
Output is correct |
42 |
Correct |
50 ms |
129296 KB |
Output is correct |
43 |
Correct |
53 ms |
129328 KB |
Output is correct |
44 |
Correct |
48 ms |
129200 KB |
Output is correct |
45 |
Correct |
54 ms |
129228 KB |
Output is correct |
46 |
Correct |
51 ms |
129304 KB |
Output is correct |
47 |
Correct |
56 ms |
129436 KB |
Output is correct |
48 |
Correct |
50 ms |
129228 KB |
Output is correct |
49 |
Correct |
51 ms |
129224 KB |
Output is correct |
50 |
Correct |
49 ms |
129224 KB |
Output is correct |
51 |
Correct |
51 ms |
129244 KB |
Output is correct |
52 |
Correct |
48 ms |
129224 KB |
Output is correct |
53 |
Correct |
52 ms |
129228 KB |
Output is correct |
54 |
Correct |
49 ms |
129228 KB |
Output is correct |
55 |
Correct |
51 ms |
129228 KB |
Output is correct |
56 |
Correct |
49 ms |
129212 KB |
Output is correct |
57 |
Correct |
52 ms |
129256 KB |
Output is correct |
58 |
Correct |
50 ms |
129320 KB |
Output is correct |
59 |
Correct |
91 ms |
129340 KB |
Output is correct |
60 |
Correct |
70 ms |
129216 KB |
Output is correct |
61 |
Correct |
91 ms |
129332 KB |
Output is correct |
62 |
Correct |
72 ms |
129420 KB |
Output is correct |
63 |
Correct |
92 ms |
129332 KB |
Output is correct |
64 |
Correct |
71 ms |
129320 KB |
Output is correct |
65 |
Correct |
83 ms |
129324 KB |
Output is correct |
66 |
Correct |
85 ms |
129248 KB |
Output is correct |
67 |
Correct |
77 ms |
129324 KB |
Output is correct |
68 |
Correct |
79 ms |
129368 KB |
Output is correct |
69 |
Correct |
86 ms |
129212 KB |
Output is correct |
70 |
Correct |
85 ms |
129320 KB |
Output is correct |
71 |
Correct |
84 ms |
129452 KB |
Output is correct |
72 |
Correct |
85 ms |
129328 KB |
Output is correct |
73 |
Correct |
84 ms |
129336 KB |
Output is correct |
74 |
Correct |
78 ms |
129296 KB |
Output is correct |
75 |
Correct |
79 ms |
129320 KB |
Output is correct |
76 |
Correct |
89 ms |
129328 KB |
Output is correct |
77 |
Correct |
90 ms |
129328 KB |
Output is correct |
78 |
Correct |
76 ms |
129212 KB |
Output is correct |
79 |
Correct |
80 ms |
129340 KB |
Output is correct |
80 |
Correct |
88 ms |
129324 KB |
Output is correct |
81 |
Correct |
78 ms |
129212 KB |
Output is correct |
82 |
Correct |
79 ms |
129256 KB |
Output is correct |
83 |
Correct |
90 ms |
129216 KB |
Output is correct |
84 |
Correct |
84 ms |
129324 KB |
Output is correct |
85 |
Correct |
83 ms |
129240 KB |
Output is correct |
86 |
Correct |
83 ms |
129256 KB |
Output is correct |
87 |
Correct |
82 ms |
129304 KB |
Output is correct |
88 |
Correct |
95 ms |
129324 KB |
Output is correct |
89 |
Correct |
91 ms |
129212 KB |
Output is correct |
90 |
Correct |
78 ms |
129424 KB |
Output is correct |
91 |
Correct |
91 ms |
129328 KB |
Output is correct |
92 |
Correct |
92 ms |
129256 KB |
Output is correct |
93 |
Correct |
86 ms |
129408 KB |
Output is correct |