#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
}
void ran() {
srand(chrono::steady_clock::now().time_since_epoch().count());
}
long long get_rand() {
long long a = rand();
long long b = rand();
return a * (RAND_MAX + 1ll) + b;
}
void usaco() {
freopen("problem.in", "r", stdin);
freopen("problem.out", "w", stdout);
}
template<typename T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;
#define endl '\n'
// #define double long double
#define int long long
// const int MOD = 1000 * 1000 * 1000 + 7;
// const int MOD = 998244353;
// #define cerr if(0) cerr
#define debug(x) cerr << #x << ": " << x << endl;
int n, len;
const int MXN = 205;
int pos[MXN], by[MXN];
int dp[MXN][MXN][2][MXN];
priority_queue<pair<int, pair<pair<int, int>, pair<int, int>>>, vector<pair<int, pair<pair<int, int>, pair<int, int>>>>, greater<pair<int, pair<pair<int, int>, pair<int, int>>>>> proc;
bool can(int l, int r) {
if (r + 1 == l) return true;
if (l == 1 && r == n) return true;
return false;
}
int prev(int x) {
if (x == 1) return n;
return x - 1;
}
int next(int x) {
if (x == n) return 1;
return x + 1;
}
signed main() {
ran(); fast();
cin >> n >> len;
for (int i=1; i<=n; i++) {
cin >> pos[i];
}
for (int i=1; i<=n; i++) {
cin >> by[i];
}
if (n == 1) {
if (min(pos[1], len - pos[1]) <= by[1]) cout << 1 << endl;
else cout << 0 << endl;
return 0;
}
for (int i=1; i<=n; i++) {
for (int j=1; j<=n; j++) {
for (int f=0; f<2; f++) {
for (int g=0; g<=n; g++) {
dp[i][j][f][g] = LLONG_MAX;
}
}
}
}
proc.push({pos[1], {{1, 1}, {0, pos[1] <= by[1]}}});
proc.push({len-pos[n], {{n, n}, {1, (len - pos[n]) <= by[n]}}});
dp[1][1][0][pos[1] <= by[1]] = pos[1];
dp[n][n][1][(len - pos[n]) <= by[n]] = len - pos[n];
int lr = 0;
for (int isi=0; isi<=n; isi++) {
for (int l=1; l<=n; l++) {
int r = prev(((l - 1 + isi) % n) + 1);
for (int f=0; f<2; f++) {
for (int taken=0; taken<=n; taken++) {
if (dp[l][r][f][taken] == LLONG_MAX) continue;
int mtime = dp[l][r][f][taken];
lr = max(lr, taken);
int at = (f == 0 ? pos[l] : pos[r]);
if (can(l, r)) continue;
{
int before = prev(l);
int dist = abs(at - pos[before]);
int will = min(dist, len - dist) + mtime;
int ntaken = taken + (will <= by[before]);
dp[before][r][0][ntaken] = min(will, dp[before][r][0][ntaken]);
}
{
int after = next(r);
int dist = abs(at - pos[after]);
int will = min(dist, len - dist) + mtime;
int ntaken = taken + (will <= by[after]);
dp[l][after][1][ntaken] = min(will, dp[l][after][1][ntaken]);
}
}
}
}
}
cout << lr << endl;
}
Compilation message
ho_t3.cpp: In function 'void usaco()':
ho_t3.cpp:15:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen("problem.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:16:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | freopen("problem.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
588 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
0 ms |
460 KB |
Output is correct |
8 |
Correct |
0 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
13 |
Correct |
0 ms |
716 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
0 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
716 KB |
Output is correct |
17 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
588 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
0 ms |
460 KB |
Output is correct |
8 |
Correct |
0 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
13 |
Correct |
0 ms |
716 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
0 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
716 KB |
Output is correct |
17 |
Correct |
1 ms |
716 KB |
Output is correct |
18 |
Correct |
1 ms |
972 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
0 ms |
716 KB |
Output is correct |
21 |
Correct |
1 ms |
972 KB |
Output is correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
1 ms |
844 KB |
Output is correct |
25 |
Correct |
1 ms |
972 KB |
Output is correct |
26 |
Correct |
1 ms |
972 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
588 KB |
Output is correct |
29 |
Correct |
1 ms |
1084 KB |
Output is correct |
30 |
Correct |
1 ms |
1100 KB |
Output is correct |
31 |
Correct |
1 ms |
972 KB |
Output is correct |
32 |
Correct |
1 ms |
876 KB |
Output is correct |
33 |
Correct |
1 ms |
1100 KB |
Output is correct |
34 |
Correct |
1 ms |
1100 KB |
Output is correct |
35 |
Correct |
1 ms |
1100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
588 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
0 ms |
460 KB |
Output is correct |
8 |
Correct |
0 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
13 |
Correct |
0 ms |
716 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
0 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
716 KB |
Output is correct |
17 |
Correct |
1 ms |
716 KB |
Output is correct |
18 |
Correct |
84 ms |
103852 KB |
Output is correct |
19 |
Correct |
49 ms |
62796 KB |
Output is correct |
20 |
Correct |
23 ms |
33356 KB |
Output is correct |
21 |
Correct |
43 ms |
59340 KB |
Output is correct |
22 |
Correct |
60 ms |
76988 KB |
Output is correct |
23 |
Correct |
21 ms |
28364 KB |
Output is correct |
24 |
Correct |
13 ms |
22216 KB |
Output is correct |
25 |
Correct |
20 ms |
27860 KB |
Output is correct |
26 |
Correct |
6 ms |
10572 KB |
Output is correct |
27 |
Correct |
21 ms |
29048 KB |
Output is correct |
28 |
Correct |
13 ms |
20652 KB |
Output is correct |
29 |
Correct |
21 ms |
29656 KB |
Output is correct |
30 |
Correct |
15 ms |
23244 KB |
Output is correct |
31 |
Correct |
19 ms |
27724 KB |
Output is correct |
32 |
Correct |
9 ms |
14540 KB |
Output is correct |
33 |
Correct |
19 ms |
27740 KB |
Output is correct |
34 |
Correct |
5 ms |
9804 KB |
Output is correct |
35 |
Correct |
15 ms |
27252 KB |
Output is correct |
36 |
Correct |
8 ms |
12876 KB |
Output is correct |
37 |
Correct |
18 ms |
29052 KB |
Output is correct |
38 |
Correct |
10 ms |
15820 KB |
Output is correct |
39 |
Correct |
18 ms |
30156 KB |
Output is correct |
40 |
Correct |
11 ms |
17612 KB |
Output is correct |
41 |
Correct |
114 ms |
128324 KB |
Output is correct |
42 |
Correct |
50 ms |
86260 KB |
Output is correct |
43 |
Correct |
113 ms |
128176 KB |
Output is correct |
44 |
Correct |
47 ms |
85060 KB |
Output is correct |
45 |
Correct |
115 ms |
128096 KB |
Output is correct |
46 |
Correct |
49 ms |
86196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
588 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
0 ms |
460 KB |
Output is correct |
8 |
Correct |
0 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
13 |
Correct |
0 ms |
716 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
0 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
716 KB |
Output is correct |
17 |
Correct |
1 ms |
716 KB |
Output is correct |
18 |
Correct |
1 ms |
972 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
0 ms |
716 KB |
Output is correct |
21 |
Correct |
1 ms |
972 KB |
Output is correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
1 ms |
844 KB |
Output is correct |
25 |
Correct |
1 ms |
972 KB |
Output is correct |
26 |
Correct |
1 ms |
972 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
588 KB |
Output is correct |
29 |
Correct |
1 ms |
1084 KB |
Output is correct |
30 |
Correct |
1 ms |
1100 KB |
Output is correct |
31 |
Correct |
1 ms |
972 KB |
Output is correct |
32 |
Correct |
1 ms |
876 KB |
Output is correct |
33 |
Correct |
1 ms |
1100 KB |
Output is correct |
34 |
Correct |
1 ms |
1100 KB |
Output is correct |
35 |
Correct |
1 ms |
1100 KB |
Output is correct |
36 |
Correct |
84 ms |
103852 KB |
Output is correct |
37 |
Correct |
49 ms |
62796 KB |
Output is correct |
38 |
Correct |
23 ms |
33356 KB |
Output is correct |
39 |
Correct |
43 ms |
59340 KB |
Output is correct |
40 |
Correct |
60 ms |
76988 KB |
Output is correct |
41 |
Correct |
21 ms |
28364 KB |
Output is correct |
42 |
Correct |
13 ms |
22216 KB |
Output is correct |
43 |
Correct |
20 ms |
27860 KB |
Output is correct |
44 |
Correct |
6 ms |
10572 KB |
Output is correct |
45 |
Correct |
21 ms |
29048 KB |
Output is correct |
46 |
Correct |
13 ms |
20652 KB |
Output is correct |
47 |
Correct |
21 ms |
29656 KB |
Output is correct |
48 |
Correct |
15 ms |
23244 KB |
Output is correct |
49 |
Correct |
19 ms |
27724 KB |
Output is correct |
50 |
Correct |
9 ms |
14540 KB |
Output is correct |
51 |
Correct |
19 ms |
27740 KB |
Output is correct |
52 |
Correct |
5 ms |
9804 KB |
Output is correct |
53 |
Correct |
15 ms |
27252 KB |
Output is correct |
54 |
Correct |
8 ms |
12876 KB |
Output is correct |
55 |
Correct |
18 ms |
29052 KB |
Output is correct |
56 |
Correct |
10 ms |
15820 KB |
Output is correct |
57 |
Correct |
18 ms |
30156 KB |
Output is correct |
58 |
Correct |
11 ms |
17612 KB |
Output is correct |
59 |
Correct |
114 ms |
128324 KB |
Output is correct |
60 |
Correct |
50 ms |
86260 KB |
Output is correct |
61 |
Correct |
113 ms |
128176 KB |
Output is correct |
62 |
Correct |
47 ms |
85060 KB |
Output is correct |
63 |
Correct |
115 ms |
128096 KB |
Output is correct |
64 |
Correct |
49 ms |
86196 KB |
Output is correct |
65 |
Correct |
98 ms |
115688 KB |
Output is correct |
66 |
Correct |
86 ms |
106144 KB |
Output is correct |
67 |
Correct |
83 ms |
101508 KB |
Output is correct |
68 |
Correct |
73 ms |
93624 KB |
Output is correct |
69 |
Correct |
95 ms |
114372 KB |
Output is correct |
70 |
Correct |
95 ms |
109660 KB |
Output is correct |
71 |
Correct |
87 ms |
110808 KB |
Output is correct |
72 |
Correct |
100 ms |
112028 KB |
Output is correct |
73 |
Correct |
73 ms |
103748 KB |
Output is correct |
74 |
Correct |
82 ms |
96948 KB |
Output is correct |
75 |
Correct |
85 ms |
107332 KB |
Output is correct |
76 |
Correct |
114 ms |
123184 KB |
Output is correct |
77 |
Correct |
101 ms |
123032 KB |
Output is correct |
78 |
Correct |
83 ms |
94840 KB |
Output is correct |
79 |
Correct |
81 ms |
98172 KB |
Output is correct |
80 |
Correct |
110 ms |
120564 KB |
Output is correct |
81 |
Correct |
78 ms |
99268 KB |
Output is correct |
82 |
Correct |
79 ms |
105052 KB |
Output is correct |
83 |
Correct |
117 ms |
128092 KB |
Output is correct |
84 |
Correct |
79 ms |
109632 KB |
Output is correct |
85 |
Correct |
89 ms |
119388 KB |
Output is correct |
86 |
Correct |
90 ms |
116924 KB |
Output is correct |
87 |
Correct |
90 ms |
107232 KB |
Output is correct |
88 |
Correct |
127 ms |
129560 KB |
Output is correct |
89 |
Correct |
113 ms |
129372 KB |
Output is correct |
90 |
Correct |
64 ms |
108496 KB |
Output is correct |
91 |
Correct |
125 ms |
129484 KB |
Output is correct |
92 |
Correct |
111 ms |
129468 KB |
Output is correct |
93 |
Correct |
75 ms |
126936 KB |
Output is correct |