Submission #1045007

# Submission time Handle Problem Language Result Execution time Memory
1045007 2024-08-05T15:36:03 Z TAhmed33 Collecting Stamps 3 (JOI20_ho_t3) C++
100 / 100
193 ms 131676 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 2e9;
int dp[203][203][203][2];
int n, l, a[203], t[203];
int ans (int x, int y, int z, int c) { //left, right, count, is it at right?
	if (x == n + 1 && y == 0) {
		if (z == 0) return 0;
		return inf;
	}
	if (z < 0) return inf;
	int &ret = dp[x][y][z][c];
	if (ret != -1) return ret;
	ret = inf;
	if (c == 0) {
		if (x != n + 1) {
			if (y != 0) {
				int cost = l - a[x] + a[y];
				ret = min(ret, ans(x + 1, y, z, 1) + cost);
				if (ans(x + 1, y, z - 1, 1) + cost <= t[x]) {
					ret = min(ret, ans(x + 1, y, z - 1, 1) + cost);
				}
			}
			if (x != n + 1) {
				int cost = a[x + 1] - a[x];
				ret = min(ret, ans(x + 1, y, z, 0) + cost);
				if (ans(x + 1, y, z - 1, 0) + cost <= t[x]) {
					ret = min(ret, ans(x + 1, y, z - 1, 0) + cost);
				}
			}
		}
	} else {
		if (y != 0) {
			if (x != n + 1) {
				int cost = l - a[x] + a[y];
				ret = min(ret, ans(x, y - 1, z, 0) + cost);
				if (ans(x, y - 1, z - 1, 0) + cost <= t[y]) {
					ret = min(ret, ans(x, y - 1, z - 1, 0) + cost);
				}
			}
			if (y != 0) {
				int cost = a[y] - a[y - 1];
				ret = min(ret, ans(x, y - 1, z, 1) + cost);
				if (ans(x, y - 1, z - 1, 1) + cost <= t[y]) {
					ret = min(ret, ans(x, y - 1, z - 1, 1) + cost);
				}
			}
		}
	}
	return ret;
}
void solve () {
	cin >> n >> l;
	a[0] = 0; a[n + 1] = l;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> t[i];
	}
	memset(dp, -1, sizeof(dp));
	int ret = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= n + 1; j++) {
			for (int k = j + 1; k <= n + 1; k++) {
				if (ans(k, j, i, 0) != inf || ans(k, j, i, 1) != inf) {
					ret = i;
				}
			}
		}
	}
	cout << ret << '\n';
}		
signed main () {
	ios::sync_with_stdio(0); cin.tie(0);
	int tc = 1; //cin >> tc;
	while (tc--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 131156 KB Output is correct
2 Correct 16 ms 131420 KB Output is correct
3 Correct 17 ms 131416 KB Output is correct
4 Correct 14 ms 131160 KB Output is correct
5 Correct 16 ms 131396 KB Output is correct
6 Correct 16 ms 131416 KB Output is correct
7 Correct 17 ms 131164 KB Output is correct
8 Correct 15 ms 131240 KB Output is correct
9 Correct 17 ms 131176 KB Output is correct
10 Correct 16 ms 131164 KB Output is correct
11 Correct 16 ms 131416 KB Output is correct
12 Correct 17 ms 131320 KB Output is correct
13 Correct 16 ms 131160 KB Output is correct
14 Correct 16 ms 131164 KB Output is correct
15 Correct 14 ms 131420 KB Output is correct
16 Correct 17 ms 131276 KB Output is correct
17 Correct 16 ms 131272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 131156 KB Output is correct
2 Correct 16 ms 131420 KB Output is correct
3 Correct 17 ms 131416 KB Output is correct
4 Correct 14 ms 131160 KB Output is correct
5 Correct 16 ms 131396 KB Output is correct
6 Correct 16 ms 131416 KB Output is correct
7 Correct 17 ms 131164 KB Output is correct
8 Correct 15 ms 131240 KB Output is correct
9 Correct 17 ms 131176 KB Output is correct
10 Correct 16 ms 131164 KB Output is correct
11 Correct 16 ms 131416 KB Output is correct
12 Correct 17 ms 131320 KB Output is correct
13 Correct 16 ms 131160 KB Output is correct
14 Correct 16 ms 131164 KB Output is correct
15 Correct 14 ms 131420 KB Output is correct
16 Correct 17 ms 131276 KB Output is correct
17 Correct 16 ms 131272 KB Output is correct
18 Correct 16 ms 131420 KB Output is correct
19 Correct 16 ms 131268 KB Output is correct
20 Correct 16 ms 131344 KB Output is correct
21 Correct 16 ms 131420 KB Output is correct
22 Correct 17 ms 131420 KB Output is correct
23 Correct 17 ms 131420 KB Output is correct
24 Correct 15 ms 131280 KB Output is correct
25 Correct 17 ms 131420 KB Output is correct
26 Correct 14 ms 131264 KB Output is correct
27 Correct 16 ms 131192 KB Output is correct
28 Correct 17 ms 131420 KB Output is correct
29 Correct 15 ms 131672 KB Output is correct
30 Correct 16 ms 131420 KB Output is correct
31 Correct 17 ms 131420 KB Output is correct
32 Correct 16 ms 131320 KB Output is correct
33 Correct 15 ms 131420 KB Output is correct
34 Correct 16 ms 131328 KB Output is correct
35 Correct 16 ms 131420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 131156 KB Output is correct
2 Correct 16 ms 131420 KB Output is correct
3 Correct 17 ms 131416 KB Output is correct
4 Correct 14 ms 131160 KB Output is correct
5 Correct 16 ms 131396 KB Output is correct
6 Correct 16 ms 131416 KB Output is correct
7 Correct 17 ms 131164 KB Output is correct
8 Correct 15 ms 131240 KB Output is correct
9 Correct 17 ms 131176 KB Output is correct
10 Correct 16 ms 131164 KB Output is correct
11 Correct 16 ms 131416 KB Output is correct
12 Correct 17 ms 131320 KB Output is correct
13 Correct 16 ms 131160 KB Output is correct
14 Correct 16 ms 131164 KB Output is correct
15 Correct 14 ms 131420 KB Output is correct
16 Correct 17 ms 131276 KB Output is correct
17 Correct 16 ms 131272 KB Output is correct
18 Correct 125 ms 131420 KB Output is correct
19 Correct 74 ms 131416 KB Output is correct
20 Correct 42 ms 131420 KB Output is correct
21 Correct 71 ms 131416 KB Output is correct
22 Correct 82 ms 131420 KB Output is correct
23 Correct 38 ms 131420 KB Output is correct
24 Correct 29 ms 131420 KB Output is correct
25 Correct 37 ms 131420 KB Output is correct
26 Correct 17 ms 131416 KB Output is correct
27 Correct 35 ms 131404 KB Output is correct
28 Correct 30 ms 131420 KB Output is correct
29 Correct 37 ms 131420 KB Output is correct
30 Correct 29 ms 131416 KB Output is correct
31 Correct 34 ms 131160 KB Output is correct
32 Correct 23 ms 131416 KB Output is correct
33 Correct 35 ms 131332 KB Output is correct
34 Correct 17 ms 131416 KB Output is correct
35 Correct 34 ms 131416 KB Output is correct
36 Correct 20 ms 131364 KB Output is correct
37 Correct 36 ms 131160 KB Output is correct
38 Correct 21 ms 131420 KB Output is correct
39 Correct 32 ms 131416 KB Output is correct
40 Correct 26 ms 131416 KB Output is correct
41 Correct 172 ms 131420 KB Output is correct
42 Correct 102 ms 131416 KB Output is correct
43 Correct 175 ms 131420 KB Output is correct
44 Correct 97 ms 131416 KB Output is correct
45 Correct 164 ms 131420 KB Output is correct
46 Correct 100 ms 131420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 131156 KB Output is correct
2 Correct 16 ms 131420 KB Output is correct
3 Correct 17 ms 131416 KB Output is correct
4 Correct 14 ms 131160 KB Output is correct
5 Correct 16 ms 131396 KB Output is correct
6 Correct 16 ms 131416 KB Output is correct
7 Correct 17 ms 131164 KB Output is correct
8 Correct 15 ms 131240 KB Output is correct
9 Correct 17 ms 131176 KB Output is correct
10 Correct 16 ms 131164 KB Output is correct
11 Correct 16 ms 131416 KB Output is correct
12 Correct 17 ms 131320 KB Output is correct
13 Correct 16 ms 131160 KB Output is correct
14 Correct 16 ms 131164 KB Output is correct
15 Correct 14 ms 131420 KB Output is correct
16 Correct 17 ms 131276 KB Output is correct
17 Correct 16 ms 131272 KB Output is correct
18 Correct 16 ms 131420 KB Output is correct
19 Correct 16 ms 131268 KB Output is correct
20 Correct 16 ms 131344 KB Output is correct
21 Correct 16 ms 131420 KB Output is correct
22 Correct 17 ms 131420 KB Output is correct
23 Correct 17 ms 131420 KB Output is correct
24 Correct 15 ms 131280 KB Output is correct
25 Correct 17 ms 131420 KB Output is correct
26 Correct 14 ms 131264 KB Output is correct
27 Correct 16 ms 131192 KB Output is correct
28 Correct 17 ms 131420 KB Output is correct
29 Correct 15 ms 131672 KB Output is correct
30 Correct 16 ms 131420 KB Output is correct
31 Correct 17 ms 131420 KB Output is correct
32 Correct 16 ms 131320 KB Output is correct
33 Correct 15 ms 131420 KB Output is correct
34 Correct 16 ms 131328 KB Output is correct
35 Correct 16 ms 131420 KB Output is correct
36 Correct 125 ms 131420 KB Output is correct
37 Correct 74 ms 131416 KB Output is correct
38 Correct 42 ms 131420 KB Output is correct
39 Correct 71 ms 131416 KB Output is correct
40 Correct 82 ms 131420 KB Output is correct
41 Correct 38 ms 131420 KB Output is correct
42 Correct 29 ms 131420 KB Output is correct
43 Correct 37 ms 131420 KB Output is correct
44 Correct 17 ms 131416 KB Output is correct
45 Correct 35 ms 131404 KB Output is correct
46 Correct 30 ms 131420 KB Output is correct
47 Correct 37 ms 131420 KB Output is correct
48 Correct 29 ms 131416 KB Output is correct
49 Correct 34 ms 131160 KB Output is correct
50 Correct 23 ms 131416 KB Output is correct
51 Correct 35 ms 131332 KB Output is correct
52 Correct 17 ms 131416 KB Output is correct
53 Correct 34 ms 131416 KB Output is correct
54 Correct 20 ms 131364 KB Output is correct
55 Correct 36 ms 131160 KB Output is correct
56 Correct 21 ms 131420 KB Output is correct
57 Correct 32 ms 131416 KB Output is correct
58 Correct 26 ms 131416 KB Output is correct
59 Correct 172 ms 131420 KB Output is correct
60 Correct 102 ms 131416 KB Output is correct
61 Correct 175 ms 131420 KB Output is correct
62 Correct 97 ms 131416 KB Output is correct
63 Correct 164 ms 131420 KB Output is correct
64 Correct 100 ms 131420 KB Output is correct
65 Correct 139 ms 131676 KB Output is correct
66 Correct 126 ms 131420 KB Output is correct
67 Correct 123 ms 131408 KB Output is correct
68 Correct 110 ms 131420 KB Output is correct
69 Correct 138 ms 131216 KB Output is correct
70 Correct 141 ms 131420 KB Output is correct
71 Correct 130 ms 131420 KB Output is correct
72 Correct 145 ms 131420 KB Output is correct
73 Correct 137 ms 131420 KB Output is correct
74 Correct 117 ms 131420 KB Output is correct
75 Correct 124 ms 131420 KB Output is correct
76 Correct 164 ms 131668 KB Output is correct
77 Correct 160 ms 131324 KB Output is correct
78 Correct 111 ms 131420 KB Output is correct
79 Correct 114 ms 131420 KB Output is correct
80 Correct 158 ms 131420 KB Output is correct
81 Correct 115 ms 131416 KB Output is correct
82 Correct 127 ms 131420 KB Output is correct
83 Correct 173 ms 131412 KB Output is correct
84 Correct 136 ms 131332 KB Output is correct
85 Correct 159 ms 131420 KB Output is correct
86 Correct 143 ms 131420 KB Output is correct
87 Correct 136 ms 131668 KB Output is correct
88 Correct 169 ms 131420 KB Output is correct
89 Correct 193 ms 131420 KB Output is correct
90 Correct 131 ms 131664 KB Output is correct
91 Correct 168 ms 131412 KB Output is correct
92 Correct 163 ms 131420 KB Output is correct
93 Correct 165 ms 131420 KB Output is correct