#include <bits/stdc++.h>
#define pii pair<int, int>
#define INF 0x3f3f3f3f
using namespace std;
int N, K, L;
priority_queue<tuple<int, int, int, int, bool>> pq;
int pos[205];
int T[205];
int dist[205][205][205][2];
int jrk[205][205];
int jarak(int a, int b) {
if(jrk[a][b] != -1) return jrk[a][b];
if(pos[a] > pos[b]) swap(a, b);
// cout << a << " " << b << " -> " << min(pos[b] - pos[a], pos[a] + L - pos[b]) << "\n";
return jrk[a][b] = min(pos[b] - pos[a], pos[a] + L - pos[b]);
}
int main() {
scanf("%d %d", &N, &L);
memset(dist, INF, sizeof(dist));
memset(jrk, -1, sizeof(jrk));
for(int i = 1; i <= N; i++) scanf("%d", &pos[i]);
for(int i = 1; i <= N; i++) scanf("%d", &T[i]);
int now = jarak(0, N);
int ada = now <= T[N] ? 1 : 0;
// cout << now << " " << ada << "\n";
pq.emplace(now, N, 0, ada, 0);
dist[N][0][ada][0] = now;
now = jarak(0, 1);
ada = now <= T[1] ? 1 : 0;
pq.emplace(now, 0, 1, ada, 1);
dist[0][1][ada][1] = now;
int poscur;
int t, l, r, cnt, side;
while(!pq.empty()) {
tie(t, l, r, cnt, side) = pq.top();
pq.pop();
if(t > 1000000000 || l - 1 == r || r + 1 == l || l == r || r == N) continue;
poscur = side ? r : l;
if(l == 0) {
now = jarak(N, poscur) + t;
ada = cnt + (now <= T[N] ? 1 : 0);
if(dist[N][r][ada][0] > now) {
dist[N][r][ada][0] = now;
pq.emplace(now, N, r, ada, 0);
}
}else {
now = jarak(poscur, l - 1) + t;
ada = cnt + (now <= T[l - 1] ? 1 : 0);
if(dist[l - 1][r][ada][0] > now) {
dist[l - 1][r][ada][0] = now;
pq.emplace(now, l - 1, r, ada, 0);
}
}
now = jarak(poscur, r + 1) + t;
ada = cnt + (now <= T[r + 1] ? 1 : 0);
if(dist[l][r + 1][ada][1] > now) {
dist[l][r + 1][ada][1] = now;
pq.emplace(now, l, r + 1, ada, 1);
}
}
int ans = 0;
for(int i = 0; i <= N; i++) {
for(int j = 0; j <= N; j++) {
for(int k = 1; k <= N; k++) {
if(k > ans && (dist[i][j][k][0] < INF || dist[i][j][k][1] < INF)) ans = k;
}
}
}
cout << ans << "\n";
cin >> N;
}
Compilation message
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &N, &L);
~~~~~^~~~~~~~~~~~~~~~~
ho_t3.cpp:24:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i = 1; i <= N; i++) scanf("%d", &pos[i]);
~~~~~^~~~~~~~~~~~~~~
ho_t3.cpp:25:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i = 1; i <= N; i++) scanf("%d", &T[i]);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
67968 KB |
Output is correct |
2 |
Correct |
40 ms |
67960 KB |
Output is correct |
3 |
Correct |
39 ms |
67968 KB |
Output is correct |
4 |
Correct |
41 ms |
67968 KB |
Output is correct |
5 |
Correct |
40 ms |
67960 KB |
Output is correct |
6 |
Correct |
39 ms |
67960 KB |
Output is correct |
7 |
Correct |
40 ms |
67960 KB |
Output is correct |
8 |
Correct |
39 ms |
68096 KB |
Output is correct |
9 |
Correct |
43 ms |
67960 KB |
Output is correct |
10 |
Correct |
39 ms |
68096 KB |
Output is correct |
11 |
Correct |
38 ms |
67960 KB |
Output is correct |
12 |
Correct |
43 ms |
67968 KB |
Output is correct |
13 |
Correct |
39 ms |
67968 KB |
Output is correct |
14 |
Correct |
39 ms |
67968 KB |
Output is correct |
15 |
Correct |
39 ms |
67968 KB |
Output is correct |
16 |
Correct |
40 ms |
67960 KB |
Output is correct |
17 |
Correct |
39 ms |
67960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
67968 KB |
Output is correct |
2 |
Correct |
40 ms |
67960 KB |
Output is correct |
3 |
Correct |
39 ms |
67968 KB |
Output is correct |
4 |
Correct |
41 ms |
67968 KB |
Output is correct |
5 |
Correct |
40 ms |
67960 KB |
Output is correct |
6 |
Correct |
39 ms |
67960 KB |
Output is correct |
7 |
Correct |
40 ms |
67960 KB |
Output is correct |
8 |
Correct |
39 ms |
68096 KB |
Output is correct |
9 |
Correct |
43 ms |
67960 KB |
Output is correct |
10 |
Correct |
39 ms |
68096 KB |
Output is correct |
11 |
Correct |
38 ms |
67960 KB |
Output is correct |
12 |
Correct |
43 ms |
67968 KB |
Output is correct |
13 |
Correct |
39 ms |
67968 KB |
Output is correct |
14 |
Correct |
39 ms |
67968 KB |
Output is correct |
15 |
Correct |
39 ms |
67968 KB |
Output is correct |
16 |
Correct |
40 ms |
67960 KB |
Output is correct |
17 |
Correct |
39 ms |
67960 KB |
Output is correct |
18 |
Correct |
38 ms |
67968 KB |
Output is correct |
19 |
Correct |
40 ms |
67960 KB |
Output is correct |
20 |
Correct |
39 ms |
67968 KB |
Output is correct |
21 |
Correct |
40 ms |
67968 KB |
Output is correct |
22 |
Correct |
42 ms |
67960 KB |
Output is correct |
23 |
Correct |
39 ms |
67968 KB |
Output is correct |
24 |
Correct |
39 ms |
67960 KB |
Output is correct |
25 |
Correct |
40 ms |
67968 KB |
Output is correct |
26 |
Correct |
46 ms |
67960 KB |
Output is correct |
27 |
Correct |
40 ms |
67968 KB |
Output is correct |
28 |
Correct |
38 ms |
67864 KB |
Output is correct |
29 |
Correct |
39 ms |
67960 KB |
Output is correct |
30 |
Correct |
39 ms |
67960 KB |
Output is correct |
31 |
Correct |
40 ms |
67960 KB |
Output is correct |
32 |
Correct |
39 ms |
67960 KB |
Output is correct |
33 |
Correct |
40 ms |
67968 KB |
Output is correct |
34 |
Correct |
47 ms |
67960 KB |
Output is correct |
35 |
Correct |
39 ms |
67960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
67968 KB |
Output is correct |
2 |
Correct |
40 ms |
67960 KB |
Output is correct |
3 |
Correct |
39 ms |
67968 KB |
Output is correct |
4 |
Correct |
41 ms |
67968 KB |
Output is correct |
5 |
Correct |
40 ms |
67960 KB |
Output is correct |
6 |
Correct |
39 ms |
67960 KB |
Output is correct |
7 |
Correct |
40 ms |
67960 KB |
Output is correct |
8 |
Correct |
39 ms |
68096 KB |
Output is correct |
9 |
Correct |
43 ms |
67960 KB |
Output is correct |
10 |
Correct |
39 ms |
68096 KB |
Output is correct |
11 |
Correct |
38 ms |
67960 KB |
Output is correct |
12 |
Correct |
43 ms |
67968 KB |
Output is correct |
13 |
Correct |
39 ms |
67968 KB |
Output is correct |
14 |
Correct |
39 ms |
67968 KB |
Output is correct |
15 |
Correct |
39 ms |
67968 KB |
Output is correct |
16 |
Correct |
40 ms |
67960 KB |
Output is correct |
17 |
Correct |
39 ms |
67960 KB |
Output is correct |
18 |
Execution timed out |
2089 ms |
67960 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
67968 KB |
Output is correct |
2 |
Correct |
40 ms |
67960 KB |
Output is correct |
3 |
Correct |
39 ms |
67968 KB |
Output is correct |
4 |
Correct |
41 ms |
67968 KB |
Output is correct |
5 |
Correct |
40 ms |
67960 KB |
Output is correct |
6 |
Correct |
39 ms |
67960 KB |
Output is correct |
7 |
Correct |
40 ms |
67960 KB |
Output is correct |
8 |
Correct |
39 ms |
68096 KB |
Output is correct |
9 |
Correct |
43 ms |
67960 KB |
Output is correct |
10 |
Correct |
39 ms |
68096 KB |
Output is correct |
11 |
Correct |
38 ms |
67960 KB |
Output is correct |
12 |
Correct |
43 ms |
67968 KB |
Output is correct |
13 |
Correct |
39 ms |
67968 KB |
Output is correct |
14 |
Correct |
39 ms |
67968 KB |
Output is correct |
15 |
Correct |
39 ms |
67968 KB |
Output is correct |
16 |
Correct |
40 ms |
67960 KB |
Output is correct |
17 |
Correct |
39 ms |
67960 KB |
Output is correct |
18 |
Correct |
38 ms |
67968 KB |
Output is correct |
19 |
Correct |
40 ms |
67960 KB |
Output is correct |
20 |
Correct |
39 ms |
67968 KB |
Output is correct |
21 |
Correct |
40 ms |
67968 KB |
Output is correct |
22 |
Correct |
42 ms |
67960 KB |
Output is correct |
23 |
Correct |
39 ms |
67968 KB |
Output is correct |
24 |
Correct |
39 ms |
67960 KB |
Output is correct |
25 |
Correct |
40 ms |
67968 KB |
Output is correct |
26 |
Correct |
46 ms |
67960 KB |
Output is correct |
27 |
Correct |
40 ms |
67968 KB |
Output is correct |
28 |
Correct |
38 ms |
67864 KB |
Output is correct |
29 |
Correct |
39 ms |
67960 KB |
Output is correct |
30 |
Correct |
39 ms |
67960 KB |
Output is correct |
31 |
Correct |
40 ms |
67960 KB |
Output is correct |
32 |
Correct |
39 ms |
67960 KB |
Output is correct |
33 |
Correct |
40 ms |
67968 KB |
Output is correct |
34 |
Correct |
47 ms |
67960 KB |
Output is correct |
35 |
Correct |
39 ms |
67960 KB |
Output is correct |
36 |
Execution timed out |
2089 ms |
67960 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |