Submission #915049

# Submission time Handle Problem Language Result Execution time Memory
915049 2024-01-23T08:55:37 Z happypotato Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
93 ms 132532 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 1e18;
const int mxN = 205;
int dp[mxN][mxN][mxN][2];
void chmin(int &x, int y) {
	x = min(x, y);
}
int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int n, l;
	cin >> n >> l;
	int x[n + 2], t[n + 1];
	x[0] = 0; x[n + 1] = l;
	for (int i = 1; i <= n; i++) cin >> x[i];
	for (int i = 0; i <= n + 1; i++) {
		for (int j = 0; j <= n + 1; j++) {
			for (int k = 0; k <= n; k++) {
				dp[i][j][k][0] = dp[i][j][k][1] = MAX;
			}
		}
	}
	for (int i = 1; i <= n; i++) cin >> t[i];
	dp[0][n + 1][0][0] = dp[0][n + 1][0][1] = 0;
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = n + 1; j > i; j--) {
			if (i == 0 && j == n + 1) continue;
			int dist;
			for (int k = 0; k <= n; k++) {
				if (i >= 1) {
					dist = x[i] - x[i - 1];
					chmin(dp[i][j][k][0], dp[i - 1][j][k][0] + dist);
					if (k && dp[i - 1][j][k - 1][0] + dist <= t[i]) {
						chmin(dp[i][j][k][0], dp[i - 1][j][k - 1][0] + dist);
					}

					dist = (l - x[j]) + x[i];
					chmin(dp[i][j][k][0], dp[i - 1][j][k][1] + dist);
					if (k && dp[i - 1][j][k - 1][1] + dist <= t[i]) {
						chmin(dp[i][j][k][0], dp[i - 1][j][k - 1][1] + dist);
					}
				}
				if (j <= n) {
					dist = x[i] + (l - x[j]);
					chmin(dp[i][j][k][1], dp[i][j + 1][k][0] + dist);
					if (k && dp[i][j + 1][k - 1][0] + dist <= t[j]) {
						chmin(dp[i][j][k][1], dp[i][j + 1][k - 1][0] + dist);
					}

					dist = x[j + 1] - x[j];
					chmin(dp[i][j][k][1], dp[i][j + 1][k][1] + dist);
					if (k && dp[i][j + 1][k - 1][1] + dist <= t[j]) {
						chmin(dp[i][j][k][1], dp[i][j + 1][k - 1][1] + dist);
					}
				}

				// cerr << i << ' ' << j << ' ' << k << ": ";
				// cerr << dp[i][j][k][0] << ' ' << dp[i][j][k][1] << endl;
				if (min(dp[i][j][k][0], dp[i][j][k][1]) < MAX) ans = max(ans, k);
			}
		}
	}
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4552 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 8624 KB Output is correct
4 Correct 1 ms 6604 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10584 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4552 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 8624 KB Output is correct
4 Correct 1 ms 6604 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10584 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 2 ms 12812 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 2 ms 12632 KB Output is correct
30 Correct 2 ms 12636 KB Output is correct
31 Correct 2 ms 10588 KB Output is correct
32 Correct 2 ms 10588 KB Output is correct
33 Correct 2 ms 12632 KB Output is correct
34 Correct 2 ms 12636 KB Output is correct
35 Correct 2 ms 12636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4552 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 8624 KB Output is correct
4 Correct 1 ms 6604 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10584 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 63 ms 111048 KB Output is correct
19 Correct 37 ms 79196 KB Output is correct
20 Correct 19 ms 58972 KB Output is correct
21 Correct 34 ms 77148 KB Output is correct
22 Correct 45 ms 90452 KB Output is correct
23 Correct 16 ms 55900 KB Output is correct
24 Correct 13 ms 52108 KB Output is correct
25 Correct 15 ms 54364 KB Output is correct
26 Correct 7 ms 39580 KB Output is correct
27 Correct 19 ms 52828 KB Output is correct
28 Correct 11 ms 51292 KB Output is correct
29 Correct 16 ms 55644 KB Output is correct
30 Correct 12 ms 51548 KB Output is correct
31 Correct 15 ms 54364 KB Output is correct
32 Correct 10 ms 45656 KB Output is correct
33 Correct 15 ms 54364 KB Output is correct
34 Correct 7 ms 37320 KB Output is correct
35 Correct 14 ms 55232 KB Output is correct
36 Correct 9 ms 43612 KB Output is correct
37 Correct 15 ms 55132 KB Output is correct
38 Correct 10 ms 47796 KB Output is correct
39 Correct 16 ms 57056 KB Output is correct
40 Correct 10 ms 48328 KB Output is correct
41 Correct 82 ms 131412 KB Output is correct
42 Correct 52 ms 97364 KB Output is correct
43 Correct 93 ms 131412 KB Output is correct
44 Correct 54 ms 96572 KB Output is correct
45 Correct 81 ms 131528 KB Output is correct
46 Correct 51 ms 97364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4552 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 8624 KB Output is correct
4 Correct 1 ms 6604 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10584 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 2 ms 12812 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 2 ms 12632 KB Output is correct
30 Correct 2 ms 12636 KB Output is correct
31 Correct 2 ms 10588 KB Output is correct
32 Correct 2 ms 10588 KB Output is correct
33 Correct 2 ms 12632 KB Output is correct
34 Correct 2 ms 12636 KB Output is correct
35 Correct 2 ms 12636 KB Output is correct
36 Correct 63 ms 111048 KB Output is correct
37 Correct 37 ms 79196 KB Output is correct
38 Correct 19 ms 58972 KB Output is correct
39 Correct 34 ms 77148 KB Output is correct
40 Correct 45 ms 90452 KB Output is correct
41 Correct 16 ms 55900 KB Output is correct
42 Correct 13 ms 52108 KB Output is correct
43 Correct 15 ms 54364 KB Output is correct
44 Correct 7 ms 39580 KB Output is correct
45 Correct 19 ms 52828 KB Output is correct
46 Correct 11 ms 51292 KB Output is correct
47 Correct 16 ms 55644 KB Output is correct
48 Correct 12 ms 51548 KB Output is correct
49 Correct 15 ms 54364 KB Output is correct
50 Correct 10 ms 45656 KB Output is correct
51 Correct 15 ms 54364 KB Output is correct
52 Correct 7 ms 37320 KB Output is correct
53 Correct 14 ms 55232 KB Output is correct
54 Correct 9 ms 43612 KB Output is correct
55 Correct 15 ms 55132 KB Output is correct
56 Correct 10 ms 47796 KB Output is correct
57 Correct 16 ms 57056 KB Output is correct
58 Correct 10 ms 48328 KB Output is correct
59 Correct 82 ms 131412 KB Output is correct
60 Correct 52 ms 97364 KB Output is correct
61 Correct 93 ms 131412 KB Output is correct
62 Correct 54 ms 96572 KB Output is correct
63 Correct 81 ms 131528 KB Output is correct
64 Correct 51 ms 97364 KB Output is correct
65 Correct 76 ms 121208 KB Output is correct
66 Correct 67 ms 113408 KB Output is correct
67 Correct 62 ms 109688 KB Output is correct
68 Correct 56 ms 103252 KB Output is correct
69 Correct 71 ms 120144 KB Output is correct
70 Correct 70 ms 116316 KB Output is correct
71 Correct 67 ms 117076 KB Output is correct
72 Correct 69 ms 118096 KB Output is correct
73 Correct 63 ms 111524 KB Output is correct
74 Correct 58 ms 105812 KB Output is correct
75 Correct 67 ms 114260 KB Output is correct
76 Correct 77 ms 127332 KB Output is correct
77 Correct 76 ms 127320 KB Output is correct
78 Correct 61 ms 104260 KB Output is correct
79 Correct 65 ms 106840 KB Output is correct
80 Correct 75 ms 125264 KB Output is correct
81 Correct 59 ms 107804 KB Output is correct
82 Correct 64 ms 112464 KB Output is correct
83 Correct 84 ms 131408 KB Output is correct
84 Correct 67 ms 116096 KB Output is correct
85 Correct 75 ms 124244 KB Output is correct
86 Correct 73 ms 122176 KB Output is correct
87 Correct 66 ms 114268 KB Output is correct
88 Correct 82 ms 132532 KB Output is correct
89 Correct 84 ms 132436 KB Output is correct
90 Correct 71 ms 115284 KB Output is correct
91 Correct 88 ms 132436 KB Output is correct
92 Correct 81 ms 132432 KB Output is correct
93 Correct 77 ms 130388 KB Output is correct