Submission #856387

# Submission time Handle Problem Language Result Execution time Memory
856387 2023-10-03T09:54:37 Z qthang2k11 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
97 ms 513104 KB
// dinhmanhhungwillwinioi2024
#include <bits/stdc++.h>
using namespace std;

const int N = 403, MAX = 1e9;

int n, limit, t[N], dp[N][N][N][2];

struct Data {
	int pos, t;
	Data(int pos = 0, int t = 0):
		pos(pos), t(t) {}
} a[N];

int32_t main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> limit;
	for (int i = 1; i <= n; i++)
		cin >> a[i].pos;
	for (int i = 1; i <= n; i++)
		cin >> a[i].t;
	if (n == 1) {
		if (a[1].pos <= a[1].t || limit - a[1].pos <= a[1].t)
			cout << 1;
		else cout << 0;
		return 0;
	}
	for (int i = 1; i <= n; i++)
		a[i + n] = a[i], a[i + n].pos += limit;
	memset(dp, 63, sizeof dp);
	bool tmp = (limit - a[n].pos) <= a[n].t;
	dp[n][n][tmp][0] = dp[n][n][tmp][1] = limit - a[n].pos;
	tmp = (a[n + 1].pos - limit <= a[n + 1].t);
	dp[n + 1][n + 1][tmp][0] = dp[n + 1][n + 1][tmp][1] = a[n + 1].pos - limit;
	int m = (n << 1), ans = 0;
	for (int l = n + 1; l > 0; l--) {
		for (int r = l; r <= m; r++) {
			for (int k = r - l + 1; k >= 0; k--) {
				for (int s = 0; s < 2; s++) {
					int cur = dp[l][r][k][s];
					if (cur > MAX || r - n >= l) continue;
					ans = max(ans, k);
					if (r + 1 <= m && (l > n || r + 1 - n < l)) {
						int cost = a[r + 1].pos - (s ? a[r].pos : a[l].pos);
						if (cost <= MAX && cur + cost < dp[l][r + 1][k + (cur + cost <= a[r + 1].t)][1])
							dp[l][r + 1][k + (cur + cost <= a[r + 1].t)][1] = cur + cost;
					}
					if (l - 1 > 0 && (r <= n || l - 1 > r - n)) {
						int cost = (s ? a[r].pos : a[l].pos) - a[l - 1].pos;
						if (cost <= MAX && cur + cost < dp[l - 1][r][k + (cur + cost <= a[l - 1].t)][0])
							dp[l - 1][r][k + (cur + cost <= a[l - 1].t)][0] = cur + cost;
					}
				}
			}
		}
	}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 55 ms 512592 KB Output is correct
2 Correct 55 ms 512664 KB Output is correct
3 Correct 56 ms 512616 KB Output is correct
4 Correct 54 ms 512592 KB Output is correct
5 Correct 55 ms 512704 KB Output is correct
6 Correct 56 ms 512592 KB Output is correct
7 Correct 54 ms 512592 KB Output is correct
8 Correct 54 ms 512592 KB Output is correct
9 Correct 57 ms 512964 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 55 ms 512532 KB Output is correct
13 Correct 57 ms 512612 KB Output is correct
14 Correct 61 ms 512752 KB Output is correct
15 Correct 58 ms 512848 KB Output is correct
16 Correct 54 ms 512596 KB Output is correct
17 Correct 54 ms 512616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 512592 KB Output is correct
2 Correct 55 ms 512664 KB Output is correct
3 Correct 56 ms 512616 KB Output is correct
4 Correct 54 ms 512592 KB Output is correct
5 Correct 55 ms 512704 KB Output is correct
6 Correct 56 ms 512592 KB Output is correct
7 Correct 54 ms 512592 KB Output is correct
8 Correct 54 ms 512592 KB Output is correct
9 Correct 57 ms 512964 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 55 ms 512532 KB Output is correct
13 Correct 57 ms 512612 KB Output is correct
14 Correct 61 ms 512752 KB Output is correct
15 Correct 58 ms 512848 KB Output is correct
16 Correct 54 ms 512596 KB Output is correct
17 Correct 54 ms 512616 KB Output is correct
18 Correct 54 ms 512628 KB Output is correct
19 Correct 54 ms 512596 KB Output is correct
20 Correct 54 ms 512596 KB Output is correct
21 Correct 55 ms 512716 KB Output is correct
22 Correct 56 ms 512692 KB Output is correct
23 Correct 54 ms 512776 KB Output is correct
24 Correct 55 ms 512760 KB Output is correct
25 Correct 55 ms 512596 KB Output is correct
26 Correct 56 ms 512588 KB Output is correct
27 Correct 55 ms 512684 KB Output is correct
28 Correct 54 ms 512564 KB Output is correct
29 Correct 54 ms 512580 KB Output is correct
30 Correct 55 ms 512592 KB Output is correct
31 Correct 54 ms 512596 KB Output is correct
32 Correct 54 ms 512596 KB Output is correct
33 Correct 54 ms 512592 KB Output is correct
34 Correct 55 ms 512760 KB Output is correct
35 Correct 54 ms 512592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 512592 KB Output is correct
2 Correct 55 ms 512664 KB Output is correct
3 Correct 56 ms 512616 KB Output is correct
4 Correct 54 ms 512592 KB Output is correct
5 Correct 55 ms 512704 KB Output is correct
6 Correct 56 ms 512592 KB Output is correct
7 Correct 54 ms 512592 KB Output is correct
8 Correct 54 ms 512592 KB Output is correct
9 Correct 57 ms 512964 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 55 ms 512532 KB Output is correct
13 Correct 57 ms 512612 KB Output is correct
14 Correct 61 ms 512752 KB Output is correct
15 Correct 58 ms 512848 KB Output is correct
16 Correct 54 ms 512596 KB Output is correct
17 Correct 54 ms 512616 KB Output is correct
18 Correct 90 ms 512592 KB Output is correct
19 Correct 73 ms 512616 KB Output is correct
20 Correct 61 ms 512596 KB Output is correct
21 Correct 68 ms 512592 KB Output is correct
22 Correct 75 ms 512708 KB Output is correct
23 Correct 59 ms 512764 KB Output is correct
24 Correct 59 ms 512700 KB Output is correct
25 Correct 60 ms 512660 KB Output is correct
26 Correct 56 ms 512600 KB Output is correct
27 Correct 60 ms 512716 KB Output is correct
28 Correct 58 ms 512692 KB Output is correct
29 Correct 61 ms 512596 KB Output is correct
30 Correct 58 ms 512596 KB Output is correct
31 Correct 60 ms 512568 KB Output is correct
32 Correct 56 ms 512776 KB Output is correct
33 Correct 60 ms 512676 KB Output is correct
34 Correct 62 ms 512568 KB Output is correct
35 Correct 59 ms 512596 KB Output is correct
36 Correct 55 ms 512628 KB Output is correct
37 Correct 60 ms 512768 KB Output is correct
38 Correct 56 ms 512592 KB Output is correct
39 Correct 61 ms 512592 KB Output is correct
40 Correct 58 ms 512596 KB Output is correct
41 Correct 97 ms 512860 KB Output is correct
42 Correct 70 ms 512596 KB Output is correct
43 Correct 93 ms 512628 KB Output is correct
44 Correct 72 ms 512780 KB Output is correct
45 Correct 94 ms 512592 KB Output is correct
46 Correct 73 ms 512652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 512592 KB Output is correct
2 Correct 55 ms 512664 KB Output is correct
3 Correct 56 ms 512616 KB Output is correct
4 Correct 54 ms 512592 KB Output is correct
5 Correct 55 ms 512704 KB Output is correct
6 Correct 56 ms 512592 KB Output is correct
7 Correct 54 ms 512592 KB Output is correct
8 Correct 54 ms 512592 KB Output is correct
9 Correct 57 ms 512964 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 55 ms 512532 KB Output is correct
13 Correct 57 ms 512612 KB Output is correct
14 Correct 61 ms 512752 KB Output is correct
15 Correct 58 ms 512848 KB Output is correct
16 Correct 54 ms 512596 KB Output is correct
17 Correct 54 ms 512616 KB Output is correct
18 Correct 54 ms 512628 KB Output is correct
19 Correct 54 ms 512596 KB Output is correct
20 Correct 54 ms 512596 KB Output is correct
21 Correct 55 ms 512716 KB Output is correct
22 Correct 56 ms 512692 KB Output is correct
23 Correct 54 ms 512776 KB Output is correct
24 Correct 55 ms 512760 KB Output is correct
25 Correct 55 ms 512596 KB Output is correct
26 Correct 56 ms 512588 KB Output is correct
27 Correct 55 ms 512684 KB Output is correct
28 Correct 54 ms 512564 KB Output is correct
29 Correct 54 ms 512580 KB Output is correct
30 Correct 55 ms 512592 KB Output is correct
31 Correct 54 ms 512596 KB Output is correct
32 Correct 54 ms 512596 KB Output is correct
33 Correct 54 ms 512592 KB Output is correct
34 Correct 55 ms 512760 KB Output is correct
35 Correct 54 ms 512592 KB Output is correct
36 Correct 90 ms 512592 KB Output is correct
37 Correct 73 ms 512616 KB Output is correct
38 Correct 61 ms 512596 KB Output is correct
39 Correct 68 ms 512592 KB Output is correct
40 Correct 75 ms 512708 KB Output is correct
41 Correct 59 ms 512764 KB Output is correct
42 Correct 59 ms 512700 KB Output is correct
43 Correct 60 ms 512660 KB Output is correct
44 Correct 56 ms 512600 KB Output is correct
45 Correct 60 ms 512716 KB Output is correct
46 Correct 58 ms 512692 KB Output is correct
47 Correct 61 ms 512596 KB Output is correct
48 Correct 58 ms 512596 KB Output is correct
49 Correct 60 ms 512568 KB Output is correct
50 Correct 56 ms 512776 KB Output is correct
51 Correct 60 ms 512676 KB Output is correct
52 Correct 62 ms 512568 KB Output is correct
53 Correct 59 ms 512596 KB Output is correct
54 Correct 55 ms 512628 KB Output is correct
55 Correct 60 ms 512768 KB Output is correct
56 Correct 56 ms 512592 KB Output is correct
57 Correct 61 ms 512592 KB Output is correct
58 Correct 58 ms 512596 KB Output is correct
59 Correct 97 ms 512860 KB Output is correct
60 Correct 70 ms 512596 KB Output is correct
61 Correct 93 ms 512628 KB Output is correct
62 Correct 72 ms 512780 KB Output is correct
63 Correct 94 ms 512592 KB Output is correct
64 Correct 73 ms 512652 KB Output is correct
65 Correct 81 ms 512592 KB Output is correct
66 Correct 81 ms 512592 KB Output is correct
67 Correct 77 ms 512596 KB Output is correct
68 Correct 74 ms 512640 KB Output is correct
69 Correct 81 ms 512596 KB Output is correct
70 Correct 79 ms 512592 KB Output is correct
71 Correct 82 ms 512596 KB Output is correct
72 Correct 80 ms 512648 KB Output is correct
73 Correct 76 ms 512596 KB Output is correct
74 Correct 77 ms 512592 KB Output is correct
75 Correct 79 ms 512528 KB Output is correct
76 Correct 86 ms 512596 KB Output is correct
77 Correct 81 ms 512592 KB Output is correct
78 Correct 77 ms 512772 KB Output is correct
79 Correct 74 ms 512776 KB Output is correct
80 Correct 84 ms 512640 KB Output is correct
81 Correct 79 ms 512592 KB Output is correct
82 Correct 79 ms 512596 KB Output is correct
83 Correct 82 ms 512848 KB Output is correct
84 Correct 86 ms 512592 KB Output is correct
85 Correct 84 ms 512596 KB Output is correct
86 Correct 82 ms 512772 KB Output is correct
87 Correct 78 ms 513104 KB Output is correct
88 Correct 85 ms 512596 KB Output is correct
89 Correct 84 ms 512584 KB Output is correct
90 Correct 77 ms 512776 KB Output is correct
91 Correct 89 ms 512672 KB Output is correct
92 Correct 85 ms 512632 KB Output is correct
93 Correct 80 ms 512764 KB Output is correct