#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 205;
ll n, l;
ll cl[N], ccl[N], t[N];
void read() {
cin >> n >> l;
cl[0] = ccl[0] = 0;
for(int i = 1; i <= n; i++) {
cin >> cl[i];
ccl[i] = l - cl[i];
}
for(int i = 1; i <= n; i++)
cin >> t[i];
}
struct state {
int l, r, cnt; bool dir;
bool operator<(const state& ot) const {
return cnt < ot.cnt;
}
};
void solve() {
priority_queue<pair<ll, state>, vector<pair<ll, state>>, greater<pair<ll, state>>> pq;
ll dist[n+2][n+2][n+2][2];
bool vis[n+2][n+2][n+2][2];
memset(dist, -1, sizeof dist);
memset(vis, 0, sizeof vis);
int ans = 0, cnt = 0;
pq.push({0, {1, n, 0, 0}});
dist[1][n][0][0] = 0;
while(!pq.empty()) {
state u = pq.top().second; pq.pop();
if(!vis[u.l][u.r][u.cnt][u.dir]) {
vis[u.l][u.r][u.cnt][u.dir] = 1;
// cerr << u.l << ' ' << u.r << ' ' << u.cnt << ' ' << u.dir << '\n';
// cerr << dist[u.l][u.r][u.cnt][u.dir] << '\n';
cnt++;
if(u.l > u.r) {
ans = max(ans, u.cnt);
continue;
}
ll cost, total;
if(u.dir == 0) {
cost = ((u.l==1)?0:-cl[u.l-1]) + cl[u.l];
total = dist[u.l][u.r][u.cnt][u.dir] + cost;
if(dist[u.l+1][u.r][u.cnt + (total <= t[u.l])][0] == -1 || dist[u.l+1][u.r][u.cnt + (total <= t[u.l])][0] > total) {
dist[u.l+1][u.r][u.cnt + (total <= t[u.l])][0] = total;
pq.push({dist[u.l+1][u.r][u.cnt + (total <= t[u.l])][0], {u.l+1, u.r, u.cnt + (total <= t[u.l]), 0}});
}
cost = ((u.l==1)?0:cl[u.l-1]) + ccl[u.r];
total = dist[u.l][u.r][u.cnt][u.dir] + cost;
if(dist[u.l][u.r-1][u.cnt + (total <= t[u.r])][1] == -1 || dist[u.l][u.r-1][u.cnt + (total <= t[u.r])][1] > total) {
dist[u.l][u.r-1][u.cnt + (total <= t[u.r])][1] = total;
pq.push({dist[u.l][u.r-1][u.cnt + (total <= t[u.r])][1], {u.l, u.r-1, u.cnt + (total <= t[u.r]), 1}});
}
} else {
cost = ((u.r==n)?0:-ccl[u.r+1]) + ccl[u.r];
total = dist[u.l][u.r][u.cnt][u.dir] + cost;
if(dist[u.l][u.r-1][u.cnt + (total <= t[u.r])][1] == -1 || dist[u.l][u.r-1][u.cnt + (total <= t[u.r])][1] > total) {
dist[u.l][u.r-1][u.cnt + (total <= t[u.r])][1] = total;
pq.push({dist[u.l][u.r-1][u.cnt + (total <= t[u.r])][1], {u.l, u.r-1, u.cnt + (total <= t[u.r]), 1}});
}
cost = ((u.r==n)?0:ccl[u.r+1]) + cl[u.l];
total = dist[u.l][u.r][u.cnt][u.dir] + cost;
if(dist[u.l+1][u.r][u.cnt + (total <= t[u.l])][0] == -1 || dist[u.l+1][u.r][u.cnt + (total <= t[u.l])][0] > total) {
dist[u.l+1][u.r][u.cnt + (total <= t[u.l])][0] = total;
pq.push({dist[u.l+1][u.r][u.cnt + (total <= t[u.l])][0], {u.l+1, u.r, u.cnt + (total <= t[u.l]), 0}});
}
}
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
read();
solve();
return 0;
}
Compilation message
ho_t3.cpp: In function 'void solve()':
ho_t3.cpp:34:27: warning: narrowing conversion of 'n' from 'll {aka long long int}' to 'int' inside { } [-Wnarrowing]
pq.push({0, {1, n, 0, 0}});
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 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 |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 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 |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
512 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 |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 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 |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
1070 ms |
117244 KB |
Output is correct |
19 |
Correct |
472 ms |
56036 KB |
Output is correct |
20 |
Correct |
128 ms |
22764 KB |
Output is correct |
21 |
Correct |
399 ms |
52056 KB |
Output is correct |
22 |
Correct |
813 ms |
79680 KB |
Output is correct |
23 |
Correct |
152 ms |
18664 KB |
Output is correct |
24 |
Correct |
43 ms |
12588 KB |
Output is correct |
25 |
Correct |
125 ms |
18180 KB |
Output is correct |
26 |
Correct |
21 ms |
4288 KB |
Output is correct |
27 |
Correct |
152 ms |
19156 KB |
Output is correct |
28 |
Correct |
37 ms |
11384 KB |
Output is correct |
29 |
Correct |
127 ms |
19732 KB |
Output is correct |
30 |
Correct |
45 ms |
13304 KB |
Output is correct |
31 |
Correct |
123 ms |
18156 KB |
Output is correct |
32 |
Correct |
38 ms |
6780 KB |
Output is correct |
33 |
Correct |
104 ms |
16624 KB |
Output is correct |
34 |
Correct |
17 ms |
4348 KB |
Output is correct |
35 |
Correct |
35 ms |
15040 KB |
Output is correct |
36 |
Correct |
21 ms |
5884 KB |
Output is correct |
37 |
Correct |
40 ms |
16764 KB |
Output is correct |
38 |
Correct |
44 ms |
7548 KB |
Output is correct |
39 |
Correct |
42 ms |
17780 KB |
Output is correct |
40 |
Correct |
28 ms |
8700 KB |
Output is correct |
41 |
Execution timed out |
2045 ms |
168136 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 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 |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
512 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 |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
512 KB |
Output is correct |
36 |
Correct |
1070 ms |
117244 KB |
Output is correct |
37 |
Correct |
472 ms |
56036 KB |
Output is correct |
38 |
Correct |
128 ms |
22764 KB |
Output is correct |
39 |
Correct |
399 ms |
52056 KB |
Output is correct |
40 |
Correct |
813 ms |
79680 KB |
Output is correct |
41 |
Correct |
152 ms |
18664 KB |
Output is correct |
42 |
Correct |
43 ms |
12588 KB |
Output is correct |
43 |
Correct |
125 ms |
18180 KB |
Output is correct |
44 |
Correct |
21 ms |
4288 KB |
Output is correct |
45 |
Correct |
152 ms |
19156 KB |
Output is correct |
46 |
Correct |
37 ms |
11384 KB |
Output is correct |
47 |
Correct |
127 ms |
19732 KB |
Output is correct |
48 |
Correct |
45 ms |
13304 KB |
Output is correct |
49 |
Correct |
123 ms |
18156 KB |
Output is correct |
50 |
Correct |
38 ms |
6780 KB |
Output is correct |
51 |
Correct |
104 ms |
16624 KB |
Output is correct |
52 |
Correct |
17 ms |
4348 KB |
Output is correct |
53 |
Correct |
35 ms |
15040 KB |
Output is correct |
54 |
Correct |
21 ms |
5884 KB |
Output is correct |
55 |
Correct |
40 ms |
16764 KB |
Output is correct |
56 |
Correct |
44 ms |
7548 KB |
Output is correct |
57 |
Correct |
42 ms |
17780 KB |
Output is correct |
58 |
Correct |
28 ms |
8700 KB |
Output is correct |
59 |
Execution timed out |
2045 ms |
168136 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |