#include <bits/stdc++.h>
#define pii tuple<int, int, int, int, bool>
#define INF 0x3f3f3f3f
using namespace std;
int N, K, L;
priority_queue<pii, vector<pii>, greater<pii>> 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]);
~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
67960 KB |
Output is correct |
2 |
Correct |
40 ms |
67960 KB |
Output is correct |
3 |
Correct |
40 ms |
67960 KB |
Output is correct |
4 |
Correct |
40 ms |
67968 KB |
Output is correct |
5 |
Correct |
39 ms |
67968 KB |
Output is correct |
6 |
Correct |
41 ms |
67960 KB |
Output is correct |
7 |
Correct |
39 ms |
67960 KB |
Output is correct |
8 |
Correct |
39 ms |
67968 KB |
Output is correct |
9 |
Correct |
39 ms |
67960 KB |
Output is correct |
10 |
Correct |
38 ms |
67968 KB |
Output is correct |
11 |
Correct |
39 ms |
67968 KB |
Output is correct |
12 |
Correct |
40 ms |
67968 KB |
Output is correct |
13 |
Correct |
41 ms |
67960 KB |
Output is correct |
14 |
Correct |
39 ms |
67968 KB |
Output is correct |
15 |
Correct |
39 ms |
67960 KB |
Output is correct |
16 |
Correct |
39 ms |
67932 KB |
Output is correct |
17 |
Correct |
39 ms |
67960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
67960 KB |
Output is correct |
2 |
Correct |
40 ms |
67960 KB |
Output is correct |
3 |
Correct |
40 ms |
67960 KB |
Output is correct |
4 |
Correct |
40 ms |
67968 KB |
Output is correct |
5 |
Correct |
39 ms |
67968 KB |
Output is correct |
6 |
Correct |
41 ms |
67960 KB |
Output is correct |
7 |
Correct |
39 ms |
67960 KB |
Output is correct |
8 |
Correct |
39 ms |
67968 KB |
Output is correct |
9 |
Correct |
39 ms |
67960 KB |
Output is correct |
10 |
Correct |
38 ms |
67968 KB |
Output is correct |
11 |
Correct |
39 ms |
67968 KB |
Output is correct |
12 |
Correct |
40 ms |
67968 KB |
Output is correct |
13 |
Correct |
41 ms |
67960 KB |
Output is correct |
14 |
Correct |
39 ms |
67968 KB |
Output is correct |
15 |
Correct |
39 ms |
67960 KB |
Output is correct |
16 |
Correct |
39 ms |
67932 KB |
Output is correct |
17 |
Correct |
39 ms |
67960 KB |
Output is correct |
18 |
Correct |
40 ms |
67960 KB |
Output is correct |
19 |
Correct |
39 ms |
67968 KB |
Output is correct |
20 |
Correct |
40 ms |
68088 KB |
Output is correct |
21 |
Correct |
38 ms |
67960 KB |
Output is correct |
22 |
Correct |
40 ms |
67968 KB |
Output is correct |
23 |
Correct |
39 ms |
67968 KB |
Output is correct |
24 |
Correct |
44 ms |
67960 KB |
Output is correct |
25 |
Correct |
39 ms |
67960 KB |
Output is correct |
26 |
Correct |
38 ms |
67968 KB |
Output is correct |
27 |
Correct |
39 ms |
67968 KB |
Output is correct |
28 |
Correct |
39 ms |
67960 KB |
Output is correct |
29 |
Correct |
39 ms |
67968 KB |
Output is correct |
30 |
Correct |
42 ms |
67960 KB |
Output is correct |
31 |
Correct |
39 ms |
67960 KB |
Output is correct |
32 |
Correct |
41 ms |
67960 KB |
Output is correct |
33 |
Correct |
39 ms |
67960 KB |
Output is correct |
34 |
Correct |
39 ms |
68092 KB |
Output is correct |
35 |
Correct |
39 ms |
67960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
67960 KB |
Output is correct |
2 |
Correct |
40 ms |
67960 KB |
Output is correct |
3 |
Correct |
40 ms |
67960 KB |
Output is correct |
4 |
Correct |
40 ms |
67968 KB |
Output is correct |
5 |
Correct |
39 ms |
67968 KB |
Output is correct |
6 |
Correct |
41 ms |
67960 KB |
Output is correct |
7 |
Correct |
39 ms |
67960 KB |
Output is correct |
8 |
Correct |
39 ms |
67968 KB |
Output is correct |
9 |
Correct |
39 ms |
67960 KB |
Output is correct |
10 |
Correct |
38 ms |
67968 KB |
Output is correct |
11 |
Correct |
39 ms |
67968 KB |
Output is correct |
12 |
Correct |
40 ms |
67968 KB |
Output is correct |
13 |
Correct |
41 ms |
67960 KB |
Output is correct |
14 |
Correct |
39 ms |
67968 KB |
Output is correct |
15 |
Correct |
39 ms |
67960 KB |
Output is correct |
16 |
Correct |
39 ms |
67932 KB |
Output is correct |
17 |
Correct |
39 ms |
67960 KB |
Output is correct |
18 |
Correct |
861 ms |
73240 KB |
Output is correct |
19 |
Correct |
416 ms |
70632 KB |
Output is correct |
20 |
Correct |
147 ms |
69360 KB |
Output is correct |
21 |
Correct |
334 ms |
70636 KB |
Output is correct |
22 |
Correct |
567 ms |
73188 KB |
Output is correct |
23 |
Correct |
170 ms |
69360 KB |
Output is correct |
24 |
Correct |
66 ms |
68660 KB |
Output is correct |
25 |
Correct |
164 ms |
69360 KB |
Output is correct |
26 |
Correct |
49 ms |
68216 KB |
Output is correct |
27 |
Correct |
170 ms |
69336 KB |
Output is correct |
28 |
Correct |
65 ms |
68316 KB |
Output is correct |
29 |
Correct |
151 ms |
68692 KB |
Output is correct |
30 |
Correct |
67 ms |
68660 KB |
Output is correct |
31 |
Correct |
158 ms |
68660 KB |
Output is correct |
32 |
Correct |
67 ms |
68660 KB |
Output is correct |
33 |
Correct |
130 ms |
68696 KB |
Output is correct |
34 |
Correct |
48 ms |
68184 KB |
Output is correct |
35 |
Correct |
62 ms |
68312 KB |
Output is correct |
36 |
Correct |
51 ms |
68568 KB |
Output is correct |
37 |
Correct |
69 ms |
68424 KB |
Output is correct |
38 |
Correct |
68 ms |
68668 KB |
Output is correct |
39 |
Correct |
70 ms |
68312 KB |
Output is correct |
40 |
Correct |
56 ms |
68312 KB |
Output is correct |
41 |
Correct |
1535 ms |
88820 KB |
Output is correct |
42 |
Correct |
53 ms |
68184 KB |
Output is correct |
43 |
Correct |
1502 ms |
88908 KB |
Output is correct |
44 |
Correct |
54 ms |
68184 KB |
Output is correct |
45 |
Correct |
1530 ms |
88656 KB |
Output is correct |
46 |
Correct |
54 ms |
68184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
67960 KB |
Output is correct |
2 |
Correct |
40 ms |
67960 KB |
Output is correct |
3 |
Correct |
40 ms |
67960 KB |
Output is correct |
4 |
Correct |
40 ms |
67968 KB |
Output is correct |
5 |
Correct |
39 ms |
67968 KB |
Output is correct |
6 |
Correct |
41 ms |
67960 KB |
Output is correct |
7 |
Correct |
39 ms |
67960 KB |
Output is correct |
8 |
Correct |
39 ms |
67968 KB |
Output is correct |
9 |
Correct |
39 ms |
67960 KB |
Output is correct |
10 |
Correct |
38 ms |
67968 KB |
Output is correct |
11 |
Correct |
39 ms |
67968 KB |
Output is correct |
12 |
Correct |
40 ms |
67968 KB |
Output is correct |
13 |
Correct |
41 ms |
67960 KB |
Output is correct |
14 |
Correct |
39 ms |
67968 KB |
Output is correct |
15 |
Correct |
39 ms |
67960 KB |
Output is correct |
16 |
Correct |
39 ms |
67932 KB |
Output is correct |
17 |
Correct |
39 ms |
67960 KB |
Output is correct |
18 |
Correct |
40 ms |
67960 KB |
Output is correct |
19 |
Correct |
39 ms |
67968 KB |
Output is correct |
20 |
Correct |
40 ms |
68088 KB |
Output is correct |
21 |
Correct |
38 ms |
67960 KB |
Output is correct |
22 |
Correct |
40 ms |
67968 KB |
Output is correct |
23 |
Correct |
39 ms |
67968 KB |
Output is correct |
24 |
Correct |
44 ms |
67960 KB |
Output is correct |
25 |
Correct |
39 ms |
67960 KB |
Output is correct |
26 |
Correct |
38 ms |
67968 KB |
Output is correct |
27 |
Correct |
39 ms |
67968 KB |
Output is correct |
28 |
Correct |
39 ms |
67960 KB |
Output is correct |
29 |
Correct |
39 ms |
67968 KB |
Output is correct |
30 |
Correct |
42 ms |
67960 KB |
Output is correct |
31 |
Correct |
39 ms |
67960 KB |
Output is correct |
32 |
Correct |
41 ms |
67960 KB |
Output is correct |
33 |
Correct |
39 ms |
67960 KB |
Output is correct |
34 |
Correct |
39 ms |
68092 KB |
Output is correct |
35 |
Correct |
39 ms |
67960 KB |
Output is correct |
36 |
Correct |
861 ms |
73240 KB |
Output is correct |
37 |
Correct |
416 ms |
70632 KB |
Output is correct |
38 |
Correct |
147 ms |
69360 KB |
Output is correct |
39 |
Correct |
334 ms |
70636 KB |
Output is correct |
40 |
Correct |
567 ms |
73188 KB |
Output is correct |
41 |
Correct |
170 ms |
69360 KB |
Output is correct |
42 |
Correct |
66 ms |
68660 KB |
Output is correct |
43 |
Correct |
164 ms |
69360 KB |
Output is correct |
44 |
Correct |
49 ms |
68216 KB |
Output is correct |
45 |
Correct |
170 ms |
69336 KB |
Output is correct |
46 |
Correct |
65 ms |
68316 KB |
Output is correct |
47 |
Correct |
151 ms |
68692 KB |
Output is correct |
48 |
Correct |
67 ms |
68660 KB |
Output is correct |
49 |
Correct |
158 ms |
68660 KB |
Output is correct |
50 |
Correct |
67 ms |
68660 KB |
Output is correct |
51 |
Correct |
130 ms |
68696 KB |
Output is correct |
52 |
Correct |
48 ms |
68184 KB |
Output is correct |
53 |
Correct |
62 ms |
68312 KB |
Output is correct |
54 |
Correct |
51 ms |
68568 KB |
Output is correct |
55 |
Correct |
69 ms |
68424 KB |
Output is correct |
56 |
Correct |
68 ms |
68668 KB |
Output is correct |
57 |
Correct |
70 ms |
68312 KB |
Output is correct |
58 |
Correct |
56 ms |
68312 KB |
Output is correct |
59 |
Correct |
1535 ms |
88820 KB |
Output is correct |
60 |
Correct |
53 ms |
68184 KB |
Output is correct |
61 |
Correct |
1502 ms |
88908 KB |
Output is correct |
62 |
Correct |
54 ms |
68184 KB |
Output is correct |
63 |
Correct |
1530 ms |
88656 KB |
Output is correct |
64 |
Correct |
54 ms |
68184 KB |
Output is correct |
65 |
Correct |
103 ms |
68664 KB |
Output is correct |
66 |
Correct |
124 ms |
68660 KB |
Output is correct |
67 |
Correct |
94 ms |
68716 KB |
Output is correct |
68 |
Correct |
92 ms |
68660 KB |
Output is correct |
69 |
Correct |
138 ms |
69364 KB |
Output is correct |
70 |
Correct |
236 ms |
70632 KB |
Output is correct |
71 |
Correct |
74 ms |
68312 KB |
Output is correct |
72 |
Correct |
269 ms |
69316 KB |
Output is correct |
73 |
Correct |
190 ms |
69484 KB |
Output is correct |
74 |
Correct |
210 ms |
69412 KB |
Output is correct |
75 |
Correct |
67 ms |
68440 KB |
Output is correct |
76 |
Correct |
1085 ms |
73372 KB |
Output is correct |
77 |
Correct |
77 ms |
68312 KB |
Output is correct |
78 |
Correct |
706 ms |
70632 KB |
Output is correct |
79 |
Correct |
77 ms |
68312 KB |
Output is correct |
80 |
Correct |
1035 ms |
73208 KB |
Output is correct |
81 |
Correct |
71 ms |
68312 KB |
Output is correct |
82 |
Correct |
462 ms |
73188 KB |
Output is correct |
83 |
Correct |
74 ms |
68312 KB |
Output is correct |
84 |
Correct |
481 ms |
73188 KB |
Output is correct |
85 |
Correct |
517 ms |
73188 KB |
Output is correct |
86 |
Correct |
535 ms |
73188 KB |
Output is correct |
87 |
Correct |
93 ms |
68440 KB |
Output is correct |
88 |
Correct |
273 ms |
70636 KB |
Output is correct |
89 |
Correct |
77 ms |
68440 KB |
Output is correct |
90 |
Correct |
66 ms |
68216 KB |
Output is correct |
91 |
Correct |
302 ms |
70608 KB |
Output is correct |
92 |
Correct |
89 ms |
68440 KB |
Output is correct |
93 |
Correct |
63 ms |
68216 KB |
Output is correct |